There is a number 256.52 , how to get the remaining number after the point?
var number = 256.52; console.log(parseInt(number)) // тут получили целое число There is a number 256.52 , how to get the remaining number after the point?
var number = 256.52; console.log(parseInt(number)) // тут получили целое число function fractionAsInt(value) { var str = ("" + value).split(".")[1]; return str? +str : 0; } console.log(fractionAsInt(256.52)); console.log(fractionAsInt(-256.52)); console.log(fractionAsInt(256)); You just have to take the remainder of the division by one.
However, it is worth noting that, since real numbers are not always exactly representable, some insignificant deviations may occur, i.e., before showing the user the number should be rounded to the desired number of characters:
console.log(256.52 % 1) console.log(-256.52 % 1) console.log(.1 + .2) console.log((256.52 % 1).toFixed(3)) console.log((-256.52 % 1).toFixed(3)) console.log((.1 + .2).toFixed(3)) Source: https://ru.stackoverflow.com/questions/892324/
All Articles
52- Puvvl