Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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
 
Old June 24th, 2003, 11:23 AM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default A weird problem with floating point ?

Hi, i met a very weird problem.
May be some know why!

Here is a example of the bug:

<html><head></head><body>

<script language='javascript'>

var v1=1.65; var v2=1.32;

alert(v1+v2);

</script>

</body></html>

When i execute this page, i get the following result : 2.9699999999999997

What 's happen ?
 
Old June 25th, 2003, 06:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Its because computers work in binary! Decimal numbers cannot always be converted precisely into a binary equivalent. This results in a lack of precision when using floating point numbers.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Floating Point Accuracy righty Java Basics 0 January 28th, 2007 12:35 AM
Formating Floating point atoyot Visual Basic 2005 Basics 2 April 26th, 2006 08:36 PM
Comparing floating point variables patpicos BOOK: Beginning Java 2, JDK 5 Edition 0 February 1st, 2005 12:37 AM
weird problem! Please Help johnjohn Classic ASP Databases 5 December 21st, 2004 10:27 AM





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