3500856AB
3500856AB

Reputation: 21

I would like to remove the decimal point in javascript / jquery

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

Answers (3)

SK.
SK.

Reputation: 4358

toFixed()

Try this method. It will help you.

Upvotes: 0

Leo
Leo

Reputation: 293

Use

 parseInt(comp2,10)

That will convert it to a decimal int

Upvotes: 0

Arun P Johny
Arun P Johny

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

Related Questions