Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript number format issue

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hello All,

I'm calling below mentioned server-side JavaScript code multiple times for different dates. When I call the function first time the varibale shows correct value -.89. When I call the function again for next date it shows -.9400000000000001 instead of -.94. If I run the query in SQL Plus it is returning -.94. Any ideas why it is happening like this ? Really appreciate any suggestions.

function DailyReport_Data(rptDate) {

// Code to execute SQL
:
:
// Code to read values
var totOutCashItems;
totOutCashItems = sqlCurs.totOutCashItems;
debug(totOutCashItems);
}

Debug message: -.89
Debug message: -.9400000000000001

Thanks much.
 
Take a look at this link, it explains it all:


-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
Thanks for the response. I code I mentioned is server-side JavaScript not client-side so it's not browser issue. Do you think it's the samething causing this issue ? I'm not doing any calculation. I'm confused.
 
floats are known to add or subtract a crazy small value like that. The only thing I can say is that you use the .toFixed() method to cut those values off.

Example:
Code:
totOutCashItems = parseFloat(sqlCurs.totOutCashItems).toFixed(2);



[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top