473,509 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug! Format statement introduces a round off

RD
The statements

The value passed to Amount by the function call is 111111111111111.98 and is
a double

then we 4execute the following code snippet

Dim New_amt as string
New_amt = Format(amount, "000000000000000.00")

The new_amt value returned is

"111111111111112.00"

Which is wrong.

Does any one know why and how to work around thisÉ

Thanks

Bob
Nov 21 '05 #1
4 1439
It's not a bug. The value you're passing into Format has more significant
digits than the double data type can handle, so it's not unreasonable to see
roundoff with values like that. For double-precision variables you get
around fifteen or sixteen significant digits, depending on the value. If you
need more significant digits, use the Decimal type, which has (I think)
twenty-seven significant digits.

Tom Dacon
Dacon Software Consulting

"RD" <no****@nospam.net> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
The statements

The value passed to Amount by the function call is 111111111111111.98 and
is
a double

then we 4execute the following code snippet

Dim New_amt as string
New_amt = Format(amount, "000000000000000.00")

The new_amt value returned is

"111111111111112.00"

Which is wrong.

Does any one know why and how to work around thisÉ

Thanks

Bob

Nov 21 '05 #2
"RD" <no****@nospam.net> schrieb:
The value passed to Amount by the function call is
111111111111111.98 and is a double

then we 4execute the following code snippet

Dim New_amt as string
New_amt = Format(amount, "000000000000000.00")

The new_amt value returned is

"111111111111112.00"


That's not a bug. The floating point number literal 111....1.98 cannot be
represented in a 'Double'.

<URL:http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html>
<URL:http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html>
<URL:http://support.microsoft.com/?scid=kb;[LN];42980>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3
RD
Can you tell me what I can use to correctly represent it, that would be very
helpfull

Thank you for your help.

Bob
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
"RD" <no****@nospam.net> schrieb:
The value passed to Amount by the function call is
111111111111111.98 and is a double

then we 4execute the following code snippet

Dim New_amt as string
New_amt = Format(amount, "000000000000000.00")

The new_amt value returned is

"111111111111112.00"
That's not a bug. The floating point number literal 111....1.98 cannot be
represented in a 'Double'.

<URL:http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html> <URL:http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html>
<URL:http://support.microsoft.com/?scid=kb;[LN];42980>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4
RD,
As Tom suggested, a System.Decimal value.

Something like:

Dim amount As Decimal = 111111111111111.98D
Dim New_amt As String
New_amt = amount.ToString("000000000000000.00")

FWIW: The D on 111111111111111.98D indicates that it is a Decimal literal,
where as 111111111111111.98 is a Double literal and 111111111111111.98F is a
Single literal.

Hope this helps
Jay

"RD" <no****@nospam.net> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl...
Can you tell me what I can use to correctly represent it, that would be
very
helpfull

Thank you for your help.

Bob
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
"RD" <no****@nospam.net> schrieb:
> The value passed to Amount by the function call is
> 111111111111111.98 and is a double
>
> then we 4execute the following code snippet
>
> Dim New_amt as string
> New_amt = Format(amount, "000000000000000.00")
>
> The new_amt value returned is
>
> "111111111111112.00"


That's not a bug. The floating point number literal 111....1.98 cannot
be
represented in a 'Double'.

<URL:http://research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html>
<URL:http://www.math.grin.edu/~stone/courses/fundamentals/IEEE-reals.html>
<URL:http://support.microsoft.com/?scid=kb;[LN];42980>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6515
by: Baoqiu Cui | last post by:
Today I was playing with a small Python program using Python 2.4 on Cygwin (up-to-date version, on Windows XP), but ran into a strange error on the following small program (named bug.py): ...
7
2197
by: delerious | last post by:
I just found a bug that's related to positioning in IE 5.5 (could someone please tell me if this bug exists in IE 6, and if so, if my solution works in that browser?). I don't know if this bug has...
102
6942
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
16
1710
by: Edward Diener | last post by:
After spending more than a day reducing a complicated compiler bug to a simple case I reported it to the MSDN Product Feedback Center as a bug just now. However this bug is completely stymying my...
26
2113
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
158
6283
by: Giovanni Bajo | last post by:
Hello, I just read this mail by Brett Cannon: http://mail.python.org/pipermail/python-dev/2006-October/069139.html where the "PSF infrastracture committee", after weeks of evaluation, recommends...
8
2026
by: gw7rib | last post by:
I've been bitten twice now by the same bug, and so I thought I would draw it to people's attention to try to save others the problems I've had. The bug arises when you copy code from a destructor...
0
330
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 380 open (-36) / 3658 closed (+65) / 4038 total (+29) Bugs : 965 open ( -9) / 6555 closed (+35) / 7520 total (+26) RFE : 272 open...
0
1790
by: LiveTecs | last post by:
http://www.livetecs.com TimeLive Web Collaboration Suite is an integrated suite that allows you to manage project life cycle including tasks, issues, bugs, timesheet, expense, attendance. ...
12
2020
by: Juan T. Llibre | last post by:
re: !I found an MSDN document that explains why what I'm trying to do should work Lee, From : http://www.w3.org/TR/REC-xml/ "A special attribute named xml:lang may be inserted in...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.