0

I have the following code:

 console.log("1-"+parseFloat($('#pval').text().replace(',','.')));
 console.log("2-"+parseFloat($('#pvig').text().replace(',','.')));
 console.log("3-"+parseFloat($('#potr').text().replace(',','.')));
 var aux = parseFloat($('#pval').text().replace(',','.'))+parseFloat($('#pvig').text().replace(',','.'))+parseFloat($('#potr').text().replace(',','.'));
console.log("4-"+aux);

Which returns :

1-1.5

2-2.52

3-0.18

4-4.199999999999999 //<-This is the problem

Why is this simple sum, losing 0.000000000001 ? How should I repair it? I already tried aux=Math.round(aux*100)/100;

But itsn´t actually working.

Any help will be preciated.


The values of those camps

id(pval)=1,5

id(pvig)=2,69

id(potr)=0,18

Matt
  • 74,352
  • 26
  • 153
  • 180
ivan
  • 33
  • 8
  • What are the text values of `pval`, `pvig` and `potr`? – Rory McCrossan May 28 '15 at 07:34
  • @RoryMcCrossan the question is editted with those camps added. – ivan May 28 '15 at 07:38
  • Please do not edit your question to fundamentally change it. if you have a new question, please ask it as a new question (feel free to reference your previous question if necessary). – Matt Jun 23 '15 at 20:11

0 Answers0