For example, if I have a number
$x = 340282366920938430000000000000000000000;
I want output as 340282366.92093 and not 340282366.92094 Also for a number like
$y = 23000000000;
I want the output to be 0.000000000000000000023
For example, if I have a number
$x = 340282366920938430000000000000000000000;
I want output as 340282366.92093 and not 340282366.92094 Also for a number like
$y = 23000000000;
I want the output to be 0.000000000000000000023
What you need to do is convert raws to megaNano. I had developed this solution that simply treats the values as a string, but it is in JS. I hope this can help your project with Nano!
function toMegaNano(raws) {
raws = raws.toString()
let megaNano
if (raws == "0") return "0"
if ((raws.length - 30) > 0) {
megaNano = raws.substr(0, raws.length - 30)
fraction = raws.substr(raws.length - 30, raws.length - (raws.length - 30))
if (fraction.length && parseInt(fraction) != 0) megaNano += '.' + fraction
} else {
megaNano = "0." + "0".repeat(30 - raws.length) + raws
}
while (megaNano[megaNano.length - 1] == '0') {
megaNano = megaNano.substr(0, megaNano.length - 1)
}
return megaNano
}
const raws = "340282366920938430000000000000000000000"
const mNano = toMegaNano(raws)
console.log(raws + " raws = " + mNano + " mNano")