-1

I am having regular expression using following code

var data = 0.085;
var output = "$"+data.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
console.log(output);

The problem is that it does not round off value 0.085 to 0.08. I am allowed to use this regular expression.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
amar ghodke
  • 451
  • 4
  • 23

1 Answers1

3

Try this:

var data = 0.085;
var output = Math.floor(data * 100) / 100;
console.log(output)
Satpal
  • 132,252
  • 13
  • 159
  • 168
GôTô
  • 7,974
  • 3
  • 32
  • 43