1

Is there a way to round number like: 0.203 to 0.21

Now I do this:

priceCurrent.toFixed(2);
void
  • 36,090
  • 8
  • 62
  • 107
Gurdt
  • 179
  • 16
  • 1
    Possible duplicate of [Round to at most 2 decimal places (only if necessary)](https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary) – Krzysztof Raciniewski Aug 17 '18 at 07:02
  • 1
    This should be tagged [tag:javascript]. Of course if JS already has a good way to do it jquery doesn't need to provide it. – user202729 Aug 17 '18 at 07:03

1 Answers1

3

You multiply this number with 100, take the ceil and divide by 100

console.log(Math.ceil(0.203*100)/100)
void
  • 36,090
  • 8
  • 62
  • 107
  • With all the floating point pitfalls. See https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary#comment28913957_17083793 for example.i – user202729 Aug 17 '18 at 07:01
  • @user202729, of course, I didn't handle all the cases here but specifically gave the user an idea about how he can begin solving this. – void Aug 17 '18 at 07:04