JSFiddle - React, Tailwind, and code Playground

by Göran Andersson

JavaScript

// it seems that the value is actually a string
// judging from the parseFloat calls that you have
var value = '-12.369754';
var decimalPoints = 0;

// parse it once
value = parseFloat(value);

// calculate multiplier
var m = Math.pow(10, decimalPoints);

// round the value
value = (value >= 0 ? Math.ceil(value * m) : Math.floor(value * m)) / m;

console.log(value);