HighDots Forums  

Somma di numeri con decimali

Javascript (Italian) Il linguaggio JavaScript (it.comp.lang.javascript)


Discuss Somma di numeri con decimali in the Javascript (Italian) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Alen Cappelletti
 
Posts: n/a

Default Somma di numeri con decimali - 01-09-2005 , 05:17 PM






Ciao a tutti,
sto avendo un po' di problemi con la somma di numeri di cui sopra...
ossia mi viene sempre restituita solo la parte intera.

Mi spiego.
Ho una stringa concatenata dall'elemento " > ", quindi con questo mi viene
passata una array....

---
var Total = document.getElementById('TotaleBundle').value;

var Temp1 = StrProdotto.split('>')
//Dato che č cosė "? 180"
var RealPrice = Temp1[4].substr(2);

var Somma = parseInt(Total)+parseInt(RealPrice);
//Ho provato anche cosė ma sembra ignoralo....
var Somma = parseFloat(Total)+parseFloat(RealPrice);
//E concludo...
document.getElementById('TotaleBundle').value = Somma;

Mi somma correttamente gli interi ma i decimali nada...
Sbaglio qualche cosa?

Ciao e Grazie,
Alen



Reply With Quote
  #2  
Old   
ZER0
 
Posts: n/a

Default Re: Somma di numeri con decimali - 01-09-2005 , 05:58 PM






On Sun, 09 Jan 2005 22:17:39 GMT, Alen Cappelletti wrote:

Quote:
sto avendo un po' di problemi con la somma di numeri di cui sopra...
ossia mi viene sempre restituita solo la parte intera.
Lasciami indovinare: la stringa di cui fai il parseFloat e' nel formato
"182,33" e non "182.33".

Ricordati che la virgola in informatica e' data dal punto.

--
C'ya,
ZER0 :: coder.gfxer.webDesigner();

"When you have eliminated the impossible, whatever remains,
however improbable, must be the truth." (S.H.)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.