javascript - Dynamic number.toFixed() function -
i using javascript number.tofixed() function.
my problem have explicitly mention number of fractional length below:
if number 1e11 have specifiy as
number.tofixed(2)
or if number 1e1 :
number.tofixed(1)
or if 1e0
number.tofixed(0)
i want dynamically based on whether fractions present or not. , irrespective of fractional length.
i dont want pass parameter of fixed fractional length. js should dynamically understand fractional length of it. there similar provision in js? or there similar function in java script need not explicitly pass parameter of fixed length?
var temp = number.split('.'); if (typeof temp[1] !== 'undefined') { console.log(temp[1].length); // here got } else { // 0 }
Comments
Post a Comment