Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 14th, 2006, 02:00 AM
Authorized User
Join Date: Jan 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Addition in javascript

i am trying to add 2 values in javascript.
if total=81.3 and tempval = 88.6

total = parseFloat(total) + parseFloat(tempval)

the desired o/p should be: 169.9
but the output generated is : 169.8999998

due to this value other values are affected.
what could be the problem??
Please help
Reply With Quote
  #2 (permalink)  
Old December 18th, 2006, 09:23 AM
Registered User
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

I don't know the exact reason why this may happen,but While working in my application i also come up with the same problem and solve it by rounding up in javascript.

x = parseFloat(13.6);
y = ...

total = x+y...

This solves the issue for me...

total = Math.round(total*100)/100

Reply With Quote
  #3 (permalink)  
Old December 19th, 2006, 11:06 AM
Registered User
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

this can also work..

total = total.toFixed(2).toString(10)

Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hexadecimal Addition madanshah16 XSLT 1 July 31st, 2007 07:21 AM
Addition of Textboxes rhd110 General .NET 3 June 23rd, 2007 04:49 PM
addition to errata luciano991 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 August 25th, 2006 08:29 PM
basic addition to php Adam H-W Beginning PHP 3 July 10th, 2006 09:58 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.