Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript force precision to 2 decimal numbers

// To force decimal to use only two numbers after coma, you can use this
var numberOne = 4.05;
var numberTwo = 3;
// If you use only this :
var total = numberOne * numberTwo; // This will be 12.149999999999999 (thanks JS...)
// But if you use this : 
var total = Number(numberOne * numberTwo).toFixed(2); // This will be 12.15
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #force #precision #decimal #numbers
ADD COMMENT
Topic
Name
8+1 =