468,733 Members | 1,474 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

convert double to decimal without rounding

In the example below, the 'convert.ToDecimal' removes the trailing 5.
like to get the number, in tact, moved to the decimal variable. Any
help would be greatly appreciated.

Dim dcml As Decimal
Dim dbl As Double = 544.4000244140625
dcml = Convert.ToDecimal(dbl)

Thx, Michael

P.S. I think getting the double to a string would be a workaround
should the above not be

May 2 '06 #1
3 6814

System.Convert.ToDecimal( value as double)

converts a double to a decimal. The resulting decimal 'contains 15
significant digits and is rounded using rounding to nearest.'

The 15 significant digits above are 544.400024414062 - no 5.
A decimal can handle up to 28 places of precision so the 'problem' is
with System.Convert.ToDecimal.
Not too sure what the official solution is, perhaps using

System.Convert.ToDecimal(obj as object, fmt as IFormatProvider)

will give you more digits, or (as a stopgap), converting in two stages
- left of the decimal point and right of the decimal point.

May 2 '06 #2
I gave the 'obj, iFormatProvider' a try but with no luck...its amazing
to me, assuming i'm not doing something stupid, that you can't simply
move a double to a string and it not round it. What makes MS think
everyone wants their number's rounded? I want the whole friggin'
number stored in my string..how bout an "IDontWantItRounded" argument
passed in to the 'convert.todecimal'.....surely there's lots I don't
know in this area. Sorry for the venting...but....

May 2 '06 #3

Thx for the help

May 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jeff_zhang446 | last post: by
12 posts views Thread by Alan | last post: by
1 post views Thread by =?big5?B?qM6nuw==?= | last post: by
21 posts views Thread by Aman JIANG | last post: by
2 posts views Thread by Denis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.