-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
  • 107,083
  • 22
  • 201
  • 376
amar ghodke
  • 381
  • 4
  • 23

1 Answers1

3

Try this:

var data = 0.085;
var output = Math.floor(data * 100) / 100;
console.log(output)
Satpal
  • 129,808
  • 12
  • 152
  • 166
GôTô
  • 7,875
  • 3
  • 31
  • 42