0

I need to round a number up to two digits (NOTE: that I need a solution that support positive AND negative numbers) I'm currently using toFixed(2) but that doesn't round it, I've Googled / Stack Overflow'ed but couldn't really find an answer for my situation:

const value = -0.004;
console.log(value.toFixed(2)); // 0.00
// Expected: -0.01

Anyone a clue? Keep safe.

randomKek
  • 1,108
  • 3
  • 18
  • 34
  • For 2 decimal digits, multiply by 100, then use `Math.ceil` or `Math.floor` depending on whether you want to round up or down, then divide by 100 again. If you run into floating-point issues, you can call `toFixed(2)` on it after that – CertainPerformance Apr 14 '20 at 06:28
  • can try this link similar question https://stackoverflow.com/a/11832950/9977272 – Anurag Apr 14 '20 at 06:31

0 Answers0