Giter VIP home page Giter VIP logo

Comments (5)

jamesallured avatar jamesallured commented on August 23, 2024

Hey! I like this idea a lot but I'd question how you would get around the precision of abbreviation, i.e. some people might want $151k for $150,899 instead of $150.9k. Does your implementation cover this at all?

I'm just trying to think of some similar examples that make decisions on precision but I don't think there are any in this package. I think it's probably fine to be opinionated on what it should be, i.e. if it doesn't round to a whole number, then it displays to one decimal place but would want to be clear in documentation.

from go-humanize.

lfaoro avatar lfaoro commented on August 23, 2024

you mean something like this?

#94

from go-humanize.

MikkelHJuul avatar MikkelHJuul commented on August 23, 2024

@jamesallured - https://github.com/dustin/go-humanize/blob/master/si.go#LC101

The monetary code could follow SI

@lfaoro - one could add non-shorthand notation as well
thousand, million, trillion...

I would leave out the currencies in the beginning, focus on something easy

from go-humanize.

dustin avatar dustin commented on August 23, 2024

This isn't quite universal, though. In finance, US dollars are abbreviated to million with MM (thousand thousand). In environments that use Lakh, it's super confusing. This quickly becomes a localization issue. I'm not sure how to generalize this to the different use cases since we do have different precision and localization requirements.

from go-humanize.

MikkelHJuul avatar MikkelHJuul commented on August 23, 2024

@dustin - wouldn't it be a lot simpler to have the user supply a map[float64]string

map[float64]string{
        ...
	3: "thousand", 
	6: "million", 
	9: "billion", 
        ...
}

that way you can separate the algorithm from the data.
(Decades of multiples of 1 should be handled, also, you may want to have only integer decades (in stead of float64 (how would you handle non-integer floats?))

It may require some work for building the object, that has a parser etc. but it is doable.

from go-humanize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.