Closed ghost closed 3 years ago
Are you working with BigNumbers? Regular numbers have a precision of about 16 digits only.
Yes. It's a part of my discord bot and want all numbers to be shown in their full form
On Sat, 15 Feb 2020, 11:40 Jos de Jong, notifications@github.com wrote:
Are you working with BigNumbers? Regular numbers have a precision of about 16 digits only.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/josdejong/mathjs/issues/1742?email_source=notifications&email_token=ALXVSWBGCSORV6WLF74WM2DRC7IDNA5CNFSM4KVGFGI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL3IN3Y#issuecomment-586581743, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALXVSWCSWNZYFB4W2E5H5HDRC7IDNANCNFSM4KVGFGIQ .
--
*Company and disclaimer information related to this email can be found here. https://sites.google.com/aetinet.org/academies-enterprise-trust/email-disclaimer
*
I think you're not actually working with BigNumbers that should give the following output:
math.config({ number: 'BigNumber' })
const result = math.evaluate('2837593480275824/5468930457689534768957689350476859760345768945076803945654*548345097438534853535')
console.log(result.toString())
// "2.845127553679215676780038456685211161450427105465427783234459329e-22"
BigNumbers are configured with 64 digits by default, this is configurable.
You can also look into the function format
to customize how the output is formatted (instead of using .toString()
).
Thanks, I'll try that right now
On Sat, 15 Feb 2020, 13:10 Jos de Jong, notifications@github.com wrote:
I think you're not actually working with BigNumbers that should give the following output:
math.config({ number: 'BigNumber' })const result = math.evaluate('2837593480275824/5468930457689534768957689350476859760345768945076803945654*548345097438534853535')console.log(result.toString())// "2.845127553679215676780038456685211161450427105465427783234459329e-22"
BigNumbers are configured with 64 digits by default, this is configurable.
You can also look into the function format to customize how the output is formatted (instead of using .toString()).
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/josdejong/mathjs/issues/1742?email_source=notifications&email_token=ALXVSWDVWJ3WMZSW7TEJKATRC7SVVA5CNFSM4KVGFGI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL3KGEI#issuecomment-586588945, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALXVSWF4CAEJ2IASKC5XCWLRC7SVVANCNFSM4KVGFGIQ .
--
*Company and disclaimer information related to this email can be found here. https://sites.google.com/aetinet.org/academies-enterprise-trust/email-disclaimer
*
It's just saying that it's an invalid calculation
try {
math.config({ number: 'BigNumber' })
const result = math.evaluate(args.join(' '))
message.channel.send("", {
embed: new Discord.RichEmbed()
.setDescription(resp.toString())
.setColor(jsonColor)
})
} catch (error) {
return message.channel.send(process.env.re + "Invalid Calculation")
}
(when i input the same calculation as before)
the args.join(" ")
is the same as the calculation we were doing earlier
2837593480275824/5468930457689534768957689350476859760345768945076803945654*548345097438534853535
just realised i made an error above, fixed it, but I keep getting this error now
Error: The global config is readonly.
Please create a mathjs instance if you want to change the default configuration.
Example:
import { create, all } from 'mathjs';
const mathjs = create(all);
mathjs.config({ number: 'BigNumber' });
kk. I figured it out and got to here.
const { create, all } = require('mathjs')
const math = create(all);
However, even with the math.config({ number: "BigNumber" })
, it still produces my result in standard form and not in its full form
Instead, it was 2.845127553679215676780038456685211161450427105465427783234459329e-22
You can use math.format
to choose a different way of formatting.
And format it to what? Or jsut the math.format method
On Sat, 15 Feb 2020, 18:32 Jos de Jong, notifications@github.com wrote:
You can use math.format to choose a different way of formatting.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/josdejong/mathjs/issues/1742?email_source=notifications&email_token=ALXVSWAOVQMOPIQF2ZCXUIDRDAYMZA5CNFSM4KVGFGI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL3T4MY#issuecomment-586628659, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALXVSWAPTE243FTS6MXP6RLRDAYMZANCNFSM4KVGFGIQ .
--
*Company and disclaimer information related to this email can be found here. https://sites.google.com/aetinet.org/academies-enterprise-trust/email-disclaimer
*
What output would you expect instead of 2.845127553679215676780038456685211161450427105465427783234459329e-22
?
One without the e-22
. I don't want it in standard form or shortened
On Sat, 15 Feb 2020, 19:26 Jos de Jong, notifications@github.com wrote:
What output would you expect instead of 2.845127553679215676780038456685211161450427105465427783234459329e-22?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/josdejong/mathjs/issues/1742?email_source=notifications&email_token=ALXVSWENNEALMUU6EEO2FNTRDA6WZA5CNFSM4KVGFGI2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL3VANA#issuecomment-586633268, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALXVSWH4KTWILHN6JX2OAMLRDA6WZANCNFSM4KVGFGIQ .
--
*Company and disclaimer information related to this email can be found here. https://sites.google.com/aetinet.org/academies-enterprise-trust/email-disclaimer
*
You can use math.format
to do that, just read the docs and play around with it, I think you can figure it out 😄 .
Say if we did this as a calculation:
The output is
2.845127553679215e-22
as you can see, it is in standard form.I have tried converting the answer to a string using
.toString()
however the output is still2.845127553679215e-22
. I want it to show the full-on value, instead of just being in standard form.Thanks in advance.
Here's my existing code (my discord bot)