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

Formatting BigDecimal loses precision #15203

Open
JayXon opened this issue Nov 18, 2024 · 2 comments
Open

Formatting BigDecimal loses precision #15203

JayXon opened this issue Nov 18, 2024 · 2 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric topic:stdlib:text

Comments

@JayXon
Copy link

JayXon commented Nov 18, 2024

require"big"
pi="3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587".to_big_d
puts pi.round(100)
puts "%.100f"%pi
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
3.1415926535897931159979634685441851615905761718750000000000000000000000000000000000000000000000000000

https://play.crystal-lang.org/#/r/hfg9

@JayXon JayXon added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Nov 18, 2024
@JayXon
Copy link
Author

JayXon commented Nov 18, 2024

BigFloat too

@HertzDevil
Copy link
Contributor

GMP BigFloat is fundamentally limited, so we have to reimplement everything ourselves unless we switch to MPFR: #11410

BigDecimal should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric topic:stdlib:text
Projects
None yet
Development

No branches or pull requests

2 participants