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

bug: 0.0041 * LAMPORTS_PER_SOL #2282

Closed
EdogawaDenji opened this issue Mar 8, 2024 · 5 comments
Closed

bug: 0.0041 * LAMPORTS_PER_SOL #2282

EdogawaDenji opened this issue Mar 8, 2024 · 5 comments
Labels
question Add this to close an issue with instructions on how to repost as a question on Stack Exchange

Comments

@EdogawaDenji
Copy link

0.0041 * LAMPORTS_PER_SOL equal to 4100000.0000000005?

RangeError: The number 4100000.0000000005 cannot be converted to a BigInt because it is not an integer

@EdogawaDenji EdogawaDenji added the bug Something isn't working label Mar 8, 2024
@buffalojoec
Copy link
Collaborator

That's weird. The math should evaluate to 4_100_000.

/**
 * There are 1-billion lamports in one SOL
 */
export const LAMPORTS_PER_SOL = 1000000000;

Do you have some repro code?

@lorisleiva
Copy link
Collaborator

That's just IEEE 754 maths I'm afraid.

https://www.typescriptlang.org/play?#code/MYewdgziA2CmB00QHMAUAGe70BYCMABAFQF4D626F216AlEA

I'd recommend never using floating points for handling financial values.

@steveluscher steveluscher added question Add this to close an issue with instructions on how to repost as a question on Stack Exchange and removed bug Something isn't working labels Mar 8, 2024
Copy link
Contributor

github-actions bot commented Mar 8, 2024

Hi @EdogawaDenji,

Thanks for your question!

We want to make sure to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track issues that affect the development of the Solana JavaScript SDK itself.

Questions like yours deserve a purpose-built Q&A forum. Unless there exists evidence that this is a bug with the Solana JavaScript SDK itself, please post your question to the Solana Stack Exchange using this link: https://solana.stackexchange.com/questions/ask


This automated message is a result of having added the ‘question’ tag.

@github-actions github-actions bot closed this as completed Mar 8, 2024
@steveluscher
Copy link
Collaborator

You will like what we're working on – a set of utilities to make annoying math like this possible on fixed-point integers. Follow along in #2125.

Copy link
Contributor

Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Add this to close an issue with instructions on how to repost as a question on Stack Exchange
Projects
None yet
Development

No branches or pull requests

4 participants