Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] big number calculation to small number using javascript
- Date: Wed, 24 Mar 2021 12:50:37 +0000
- From: Darren Cook <darren@example.com>
- Subject: Re: [tlug] big number calculation to small number using javascript
- References: <CAMyPCTSYgGyjrctN3P67KJ+9F76qRu_DSN7Q=F91Map3Pc3y7w@mail.gmail.com> <bb6b7debf4b4cc5fb6c559beff66d3ce@jp.sometwo.net> <CAMyPCTRAd6_yUsAwZmrQ+-H-L3tdFDWNjSs1CUN40ZgZZZ8T-A@mail.gmail.com> <b75f5c05-1727-d82d-9b4b-9422b5854568@dcook.org>
Sigh. Copy-and-paste-and-tidyup from real code, made that confusing, didn't it. If this was StackOverflow I would just have hit edit to change one of the `v1` into `s`. Better version below. Darren We use https://github.com/MikeMcl/decimal.js/ for handling potentially large numbers in text. E.g. if s is a number in string form, which might contain commas: let v1 = new Decimal(s.replace(/,/g, '')) v1 = v1.mul(multiplier) In this particular code, multiplier might be 9 if `s` was followed by "bn", or 12 if followed by "兆". You can then use toExponential, toFixed and toPrecision to create strings, or toNumber to get back to a native JS type.
- References:
- [tlug] big number calculation to small number using javascript
- From: James Tobin
- Re: [tlug] big number calculation to small number using javascript
- From: furkan
- Re: [tlug] big number calculation to small number using javascript
- From: James Tobin
- Re: [tlug] big number calculation to small number using javascript
- From: Darren Cook
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] big number calculation to small number using javascript
- Previous by thread: Re: [tlug] big number calculation to small number using javascript
- Index(es):