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

Utils.toNano and Utils.fromNano conver with precision #84

Open
qzmer1104 opened this issue Nov 25, 2024 · 1 comment
Open

Utils.toNano and Utils.fromNano conver with precision #84

qzmer1104 opened this issue Nov 25, 2024 · 1 comment

Comments

@qzmer1104
Copy link

qzmer1104 commented Nov 25, 2024

more Overloading methods
eg:

public static BigInteger toNano(BigDecimal toncoins, Integer precision);
public static BigInteger toNano(String toncoins, Integer precision);
public static BigInteger toNano(long toncoins, Integer precision);
……
public static BigDecimal fromNano(BigInteger nanoCoins, Integer precision);
public static BigDecimal fromNano(String nanoCoins, Integer precision);
public static BigDecimal fromNano(long nanoCoins, Integer precision)
……

because not all Jetton use precision 9

eg: Tether Token for Tether USD
https://tonviewer.com/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs
It's

"decimals": "6",

we must add a method by ourselves like

new BigDecimal(toncoins).multiply(BigDecimal.TEN.pow(precision)).toBigInteger();
new BigDecimal(nanoCoins).divide(BigDecimal.TEN.pow(precision), precision, RoundingMode.FLOOR);

I also discovered an Overloading method

public static BigDecimal fromNano(long nanoCoins, int scale);

Maybe you should think more carefully about adding methods.

Sincerely,

@neodix42
Copy link
Owner

Thanks for pointing this out, I will add more rounding methods with the next release.
You are also welcome to create a PR with your changes at any time. After reviewing it I will merge it, normally this speeds up the whole process.

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