Easy way to make 3.2242143 to 3.2 using jquery

I have a lot of data like this:

3.23214215

but I want to use part 3.2,

what can i do with jquery,

thank

+5
source share
4 answers

You can use simple Javascript:

var n = 3.23214215
var fixed = n.toFixed(1)
+3
source

You don't need jquery, plain old javascript does the trick:

var chopped = Math.floor(full_length * 10.0) / 10.0;
+1
source

You can do this in simple Javascript:

var f = 3.23214215;
f *= 10;
var i = parseInt(f);
f = i / 10;

You can also explore the Math object. It may have a rounding function.

0
source

All Articles