Comments (18)
FWIW replacing "G" with "B" in formatters is something I end up doing frequently.
It would be great to have somthing with that baked in.
from d3-format.
I wonder whether it would make sense to provide a user property to allow the localising of the SI letters via the d3.formatLocale() function. A user would provide an array of values to applied as a sort of "localised (or rather customised) version of SI", the default being SI itself. For the above request, this would then translate to the following user specification:
numberPrefixes : ["y","z","a","f","p","n","µ","m","","k","M","B","T","P","E","Z","Y"]
from d3-format.
Please don’t reply with “+1”. If you want to vote for this issue, click the plus smiley face +😄 at the top of this issue, and then click the 👍 button.
from d3-format.
You’d want “K” instead of “k” too, though, no?
Personally, I think it’d be surprising to have SI prefixes mixed in with units that are not SI. Would you rather see “$1,000T” (one thousand trillion dollars) or “$1P” (one petadollars)?
from d3-format.
This is the intended behavior for s
, yes; B is not an SI prefix.
There are currency equivalents in SI for ones (none), thousands (k ↦ K), millions (M), billions (G ↦ B) and trillions (T), but there aren’t equivalents for values outside this range. There’s no common symbol for a quadrillion, for instance, which would use the SI peta prefix P. (Also in finance MM is commonly used instead of M for millions, coming from the Roman for a thousand thousands.)
To support this properly we’d need a different directive than s
to format currencies.
from d3-format.
@mbostock I fully agree with that B for billion is not an SI prefix, and that s
shouldn't have to be altered, but instead, a new directive should be added.
About your comment about MM instead of M, I do agree, but I think this also depends on locale, hence my initial note about localization.
from d3-format.
I’ll also mention that number.toLocaleString supports currency formatting, although it does not appear to support abbreviated formats such as millions or billions.
https://observablehq.com/@mbostock/number-formatting
from d3-format.
+1
from d3-format.
What might a solution look like? Perhaps a new thing that is similar to s
, but a different letter?
Perhaps
const formatter = number => format('.1s')(number).replace('G', 'B');
could ideally be replaced with
const formatter = format('.1r');
Just picking r
out of a hat - could be any letter. Would this approach be reasonable?
Also noting that this issue is not really specific to currency (the "currency" in the title threw me off) - this issue is about replacing G with B generally, I believe.
from d3-format.
r
is already used; see the README. But, there are other letters free. 😄
In addition to choosing a letter for the format directive, someone needs to propose a precise definition for this feature. My impression is that this will only support K, M, B and T units? And any value outside that range will behave like the g
directive, I suppose?
from d3-format.
Strawman proposal: exactly the same behavior as s
, with the only difference being G switching to B.
from d3-format.
Digging into this a bit, found some interesting things:
I have seen million, billion, and trillion abbreviated as M, B, and T respectively. However, I would not bet that that is a standard abbreviation.
- Wikipedia: Names of Large Numbers - Interesting tables there of full names, but not abbreviations.
I get what you're saying re: values outside the range of T. The question is how to handle P (Peta-, Quadrillion), E (Exa-, Quintillion), Z (Zetta-, Sextillion), Y (Yotta-, Septillion). Indeed, maybe best leave these out, as you're right that having mixed SI plus this other thing with B (which I don't even know what it is called - "Ordinary Usage"?) would be super confusing.
OK - slightly more nuanced proposal for consideration:
- K instead of k
- M, B and T units
- Beyond T range, express as "$1,000T", "$1,000,000T" etc.
from d3-format.
And what is this format even called? Conventional written form? I'm hard-pressed to find any standard definition for this anywhere, aside from people reporting things they've seen in common use in documents over the years. Also this is definitely English-specific - I have no idea how this plays out for other languages, which is an additional challenge.
Thanks for taking the time to consider all these things!
from d3-format.
Haha we can call it "Excel Format", as Excel has this kind of formatting built-in.
Interestingly, several games have faced this challenge and documented their solutions (images are links).
I wish we could find an authoratative source on this - like a reputable dictionary or writing style guide.
from d3-format.
This is a good one - Language Matters: Millions, Billions and Other Large Numbers
The most commonly seen short forms for thousand, million, billion and trillion in North America and the United Kingdom, respectively, are outlined in the table below.
Of the style guides that address spacing in this context, most (AP Stylebook, Chicago Manual of Style, Canadian Style, The Economist Style Guide) say to leave no space (100bn, for example), although it is also common in books and newspaper articles to see the abbreviation preceded by a space.
from d3-format.
From The Economist Style Guide:
Use m for million, bn for billion and trn for trillion.
The AP Stylebook has nothing in terms of abbreviations.
from d3-format.
FWIW this is what I'm using now to solve this:
const siFormat = format('.3~s');
export const formatBigNumber = number =>
siFormat(number).replace('G', 'B').replace('k', 'K');
from d3-format.
This PR looks pretty close woohoo! #81
from d3-format.
Related Issues (20)
- import conflict with 3.0.0 update HOT 7
- Error with jest in version 3.0.0 HOT 1
- `"c"` format does not work as expected HOT 4
- Hot reload is complaining about named functions in nextjs HOT 4
- Using the locale .json files directly is not possible anymore HOT 1
- Add any string suffix to number. HOT 1
- Pick locale based on users browser automatically rather than fetching the locale definitions HOT 2
- Missing d3-format.min.js HOT 3
- Undefined Import in Next.js HOT 1
- I am using d3 in nextJs 7.0.x , it is giving error Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Home\Wildlife-Insights\node_modules\d3\package.json. HOT 1
- Using custom units in d3-format HOT 3
- Is it possible to support locale zh-TW? HOT 3
- formatPrefix will sometimes not perform rounding HOT 5
- Should functions be named across `d3-*` ? HOT 4
- Unit is generated outside parenthesis for negative numbers
- zh-TW is not supported HOT 2
- Specify type `g` decimal to exponential break point
- formatPrefix vs format handling of parentheses
- The minus sign generated by d3.format not compatible with SVG HOT 1
- d3 format transfer minus(-) to ascii 8722 code HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-format.