Reputation: 21
I would like to remove the decimal point in javascript / jquery
my code:
var comp2 = 35.99 * 10003;
var comp2gtotal;
comp2gtotal = comp2;
$(".comp2totaled").html( comp2gtotal );
<div class="comp2totaled"></div>
The answer i get is 360007.97000000003
What i need it to say is = 360007.97
or 360,007.97
without all the zeros ect at the end..
thanks..
Upvotes: 2
Views: 1782
Reputation: 388316
Try
comp2gtotal = Math.round(comp2 * 100) / 100;
$(".comp2totaled").html(comp2gtotal);
Demo: Fiddle
Or if don't want to round the 3+ decimal places then
$(".comp2totaled").html(comp2gtotal.toFixed(2));
Demo: Fiddle
Upvotes: 1