printfn / fend

Arbitrary-precision unit-aware calculator
https://printfn.github.io/fend
MIT License
590 stars 50 forks source link

Scientific notation in output #123

Open MalteT opened 2 years ago

MalteT commented 2 years ago

Allow configuration of the output format (as done with to exact/20dp/etc) but for scientific notation.

This might be possible already, but I can't figure out how to do this.

We might also allow for other notations, like those mentioned in the above Wikipedia article. I would be willing to put some work into this.

Thank You!

printfn commented 2 years ago

Thanks for raising this issue! Yeah, scientific notation is not currently supported as an output format, but I agree it’d be a really nice feature to have.

Unfortunately the whole formatting part of the code is quite a mess, but if do you feel up to implementing this I’d be super grateful :)

MalteT commented 2 years ago

Nice! Well, I've looked through the code and found BigRat::format_as_decimal, but there's a lot more for me to comprehend. I might continue this journey when I have more time at hand. I haven't seen enough code to understand how the formatting code could be simplified, but yeah, it's quite complex :D

timokoesters commented 3 months ago

Scientific notation would be very useful, I think it should follow the usual convention 1.234E12, perhaps even with an option to write it as 1.234*10^12

There should also be an option to set the number of significant digits, usually only 3 are relevant (4, if the first digit is a 1, as in the example above).