0

I'm trying to do some floating number calculation with javascript that requires high accuracy

when I tried to initiate a variable like this:

const pi = 3.141592653589793238462643383280

System will truncate number to

>pi
>3.141592653589793

How can I do calculating with long decimal digits? thanks!

jerry
  • 1,004
  • 1
  • 9
  • 17
  • 1
    `const pi = '3.141592653589793238462643383280';` – Elliott Frisch Feb 25 '18 at 07:07
  • May be you should try this. https://github.com/dtrebbien/BigDecimal.js – Arsalan Akhtar Feb 25 '18 at 07:12
  • @ElliottFrisch, sorry I mean to say calculating with long decimal digits, not just storing it, i've updated question – jerry Feb 25 '18 at 07:17
  • @ArsalanAkhtar, thanks, BigDecimal.js seems complicated, I wonder would there be any performance penalty? – jerry Feb 25 '18 at 07:19
  • Why using javascript for high accuracy? – Frederik.L Feb 25 '18 at 07:20
  • @Frederik.L, I'm trying to do some statistic work, accuracy is important to me, is javascript not the right language for this sort of work? – jerry Feb 25 '18 at 07:23
  • @jerry Not that I wouldn't be interested to see decent Javascript ways of managing high accuracy numbers, I feel like you will end up doing something near what the Python language does with "endless numbers". That is probably more efficient to use a native approach with Python instead of using a lib to recreate this in javascript. Just my two cents. – Frederik.L Feb 25 '18 at 07:26
  • @Frederik.L, thank you! – jerry Feb 25 '18 at 07:28

1 Answers1

0

You can use a library like say for example http://mikemcl.github.io/decimal.js/

Jiby Jose
  • 2,980
  • 3
  • 21
  • 31