Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format numbers as billions / millions / thousands, smartly [duplicate]

Any recipes out there for a "smart" number formatting formula that's "scale-aware," a la Rails ActionView's distance_of_time_in_words method?

I would expect to enter a number like: 1,816,724 and see 1.8M (or enter 2,394 and see 2.4K).

like image 387
jm3 Avatar asked Nov 02 '25 05:11

jm3


2 Answers

To format conditionally using Billions / Millions / Thousands in Google Spreadsheets or Excel, you can use:

[<999950]0.0,"K";[<999950000]0.0,,"M";0.0,,,"B"

enter image description here

To apply this setting in Google sheets, goto Format > Number > Custom Number Format and copy paste the above format string.

To learn more about formatting options, go to https://support.google.com/docs/answer/56470#zippy=%2Ccustom-number-formatting

like image 165
jm3 Avatar answered Nov 04 '25 18:11

jm3


Select the cells to receive a custom number format and tap Ctrl+1. When the Format Cells dialog opens, go to the Number tab and choose Custom from the list down the left side. Supply the following for the Type:,

[>999999]0.0,,\M;[>999]0.0,K;0

Note that M is a reserved character in a format mask and must be escaped with a backslash to become literal. You can also wrap it in quotes but since I use custom number formats in VBA's .NumberFormat property, I prefer the escape character to avoid having to deal with quotes within quoted strings. Your results should resemble the following:

        M and K custom number format


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!