## 6 replies

Last post Apr 20, 2016 06:47 AM by bertanyadong

Member

49 Points

147 Posts

### javascript division wrong calculation.

Hi guys i have this value but returning worng calculation,

why my result returning 2000.0000000000000 not 2 ?

dou you have solution for fix this ?

a = 1196000;
b = 598000;

result = (1196000 / 598,000 ) = 2000.0000000000000 ( if i use calculator the result is "2" not 2000.0000000000000 )

Thanks.

• raju dasa

All-Star

15176 Points

3888 Posts

### Re: javascript division wrong calculation.

Apr 18, 2016 07:44 AM|raju dasa|LINK

Hi,

I tried you calculation in firebug console, it's returning 2 but not 200.000..

Can you explain more, in which scenario this output is thrown, with code attempted.

Happy Coding ! Mark as Answer if it helps.
rajudasa.blogspot.com  ||  rajudasa-tech

Member

49 Points

147 Posts

### Re: javascript division wrong calculation.

thanks Raju.

this is my code :

i want my total returning = 2.

could you tell me whats wrong with my code ?

thanks.

```var a = 1100000;
var b =  96000;var c = 598000;

var total = 0;
total = ((Number(a) + Number(b)) / Number(c) );  ==> result 2000.0000000000000var calculate = 0;calculate =((parseFloat(a) + parseFloat(b)) / parseFloat(c) );  ==> result 2000.0000000000000 ```
• raju dasa

All-Star

15176 Points

3888 Posts

### Re: javascript division wrong calculation.

Apr 18, 2016 09:08 AM|raju dasa|LINK

Hi,

Sorry, still unable to reproduce your issue.

when in ran your code in firbug console, i get correct answer 2.

Happy Coding ! Mark as Answer if it helps.
rajudasa.blogspot.com  ||  rajudasa-tech

Member

49 Points

147 Posts

### Re: javascript division wrong calculation.

not working in my project.

• mgebhard

All-Star

38731 Points

15899 Posts

### Re: javascript division wrong calculation.

I am also unable to reproduce the behavior using the posted code snippet.  I imagine the code snippet does not reflect the actual logic.

How about returning two significant figures?

```var a = 1;
var b = 3;
var result = a / b;
console.log(result.toFixed(2));```