0

I've tried basically everything here: JavaScript math, round to two decimal places

Not only do I want to reduce it to two decimals, but if it's less I need to add a zero. I'm using .1 in my examples below.

var base = .1;  //desired result is 0.10
var total;

// the x100/100 method
total = (base * 100) / 100;
console.log(total);  //outputs 0.1

// the .toFixed method
total = (base).toFixed(2);
console.log(total + " (" + typeof total + ")"); //looks right, but it's a string

// unary +()
total = +((base).toFixed(2));
console.log(total); //outputs .1
THE JOATMON
  • 16,761
  • 34
  • 110
  • 200

0 Answers0