Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this support scientific notation? #11

Closed
BallisticPain opened this issue Apr 13, 2018 · 3 comments
Closed

Does this support scientific notation? #11

BallisticPain opened this issue Apr 13, 2018 · 3 comments

Comments

@BallisticPain
Copy link

The reason I'm asking, I'm trying to do some Unit Conversions using the https://github.com/PhpUnitsOfMeasure/php-units-of-measure library, and unfortunately with the accuracy I'm trying to have, the floats they are currently using isn't enough. I'm looking at maybe converting their library to use this library for the numbers. However for the SI Units, it's all notated in scientific notation... which I could manually convert, but why if I don't have to?

Thanks!

@BenMorel
Copy link
Member

Hi, yes it can parse numbers of any size in scientific notation:

use Brick\Math\BigDecimal;

echo BigDecimal::of('1.23456e27'); // 1234560000000000000000000000
echo BigDecimal::of('1.23456789e-31'); // 0.000000000000000000000000000000123456789

It always outputs them in full decimal notation, however, is that OK for your use case?

@BallisticPain
Copy link
Author

I believe by digging around further while trying to simply solve my immediate need, I found some spots in the source where it discusses scientific notation in the BigNumber file.

Here's a link to that for those who may look after me:

* - strings containing a `.` character or using an exponentional notation are returned as BigDecimal

@BallisticPain
Copy link
Author

@BenMorel

Thanks for the rapid response... here I am 19 hours later, never once thought I should refresh the page haha. I found it quickly.

I really like and appreciate your library. I'm doing unit conversions, and was looking into a few of the libraries. I'm intending to marry your library with one or possibly two of those.

Thanks for the example that goes even better with the link. :-D
Best and kind regards!
Jarvis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants