question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support number prefixes above billion. (quadrillion-septillion)

See original GitHub issue

Somewhat related: The trillion prefix doesn’t seem to work for me - instead I get 1undefined.

Is it possible to add the prefixes for quadrillion (P / 10^15), quintillion (E / 10^18), sextillion (Z / 10^21) and septillion (Y / 10^24)? I would have done it my self but don’t fully understand this section.

This is what I have so far:

Language:

    e.language("en", {
        delimiters: {
            thousands: ",",
            decimal: "."
        },
        abbreviations: {
            thousand: "K",
            million: "M",
            billion: "B",
            trillion: "T",
            quadrillion: "P",
            quintillion: "E",
            sextillion: "Z",
            septillion: "Y"
        },
// rest of language code
});

(Number?) function snippet

var o = new RegExp(n[r].abbreviations.thousand + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),
    u = new RegExp(n[r].abbreviations.million + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),
    a = new RegExp(n[r].abbreviations.billion + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),
    f = new RegExp(n[r].abbreviations.trillion + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),
    Pvariable = new RegExp(n[r].abbreviations.quadrillion + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),
    Evariable = new RegExp(n[r].abbreviations.quintillion + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),
    Zvariable = new RegExp(n[r].abbreviations.sextillion + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),
    Yvariable = new RegExp(n[r].abbreviations.septillion + "(?:\\)|(\\" + n[r].currency.symbol + ")?(?:\\))?)?$"),

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
danielquinncommented, Dec 9, 2015

+1

Strangely, while “trillion” is already in the library, this fails with undefined:

numeral(1000000000000).format("0.0a")
1reaction
MartinMuzatkocommented, Jun 22, 2015

I don’t know why exactly you need a regex for each unit, this is not really effective and leads to bloat very quickly.

I’d suggest to use something that scales along with the amount of units. Like so:

function commarize()
{
    var units = [
        "Million",
        "Billion",
        "Trillion",
        "Quaddrillion",
        "Quintillion",
        "Sextillion",
        "Septillion",
        "Octillion"
    ]

    if (this >= 1e6)
    {
        // Divide to get SI Unit engineering style (1e3,1e6,1e9, etc)
        var reg = Math.floor((this / 1000).toFixed(0).toString().length)
        // Calculate the remainder. 1,000,000 = 1.000 Mill
        var num = (this / ('1e'+(reg+2))).toFixed(3)
        var string = units[Math.floor(reg / 3) - 1]
        return num + ' ' + string
    }

    var parts = this.toString().split(".")
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",")

    return parts.join(".")
}

Number.prototype.commarize = commarize
String.prototype.commarize = commarize

Hope I were able to help in a way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Names of large numbers - Wikipedia
Names of numbers above a trillion are rarely used in practice; such large numbers have practical usage primarily in the scientific domain, where...
Read more >
Number words and prefixes.
Words for large numbers ; Number word. Millions scheme. Thousands scheme ; million. 10 · 10 ; billion (Latin bi-, twice). 10 ·...
Read more >
Metric Numbers - Math is Fun
"kilo" for a thousand,; "mega" for a million,; and more ... long rope ... Here we list the prefix for commonly used big...
Read more >
Large number abbreviations
Large number abbreviations ; q, Quadrillion, 10^15 ; Q · Quintillion, 10^18 ; s, Sextillion, 10^21 ; S · Septillion, 10^24 ...
Read more >
Naming Large Numbers
billion. 10 9. trillion. 10 12. quadrillion. 10 15. quintillion. 10 18. sextillion. 10 21. septillion. 10 24. octillion. 10 27. nonillion. 10...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found