473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

convert double to decimal without rounding

In the example below, the 'convert.ToDecimal' removes the trailing 5.
I'd
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)
Debug.WriteLine(dcml.ToString)

Thx, Michael

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

May 2 '06 #1
3 7114


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.
hth,
Alan.

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
Solved....
dbl.ToString("R")

Thx for the help

May 2 '06 #4

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

Similar topics

3
by: jeff_zhang446 | last post by:
Hi, I try to convert double to string as below: std::string cnvrtToString(double lValue) { std::ostringstream lStream; lStream << lValue; return lStream.str();
12
by: Alan | last post by:
how to convert double to short ? for example, I want to convert double doubleVal1 = 15000.1; double doubleVal2 = 12000.0; short shortVal; shortVal = doubleVal1 - doubleVal2; I...
1
by: | last post by:
eg. "19.121" to 19.12 decimal eg. "12.567 " to 12.56 decimal
2
by: mshahzadali | last post by:
is there any expert who could guide me making a C++ program. I want to convert a Decimal number into a Binary, Octal and a Hexadecimal Number using a C++ Built-in Function(if there exist any).
1
by: =?big5?B?qM6nuw==?= | last post by:
I already knew how to convert bytes to Double, use BitConverter.ToDouble(). but, How to convert double to bytes? for example: double a = 3,444; I want convert to bytes={ ?, ?, ?, ?, ?, ?,...
21
by: Aman JIANG | last post by:
hi I need to do this (convert double to string) fast, safe and portable. Is there any way to do this ? Except the ways following: 1. C++ I/O stream, stringstream (and boost::lexical_cast) 2....
1
by: Bjorn Brox | last post by:
Hi! In germany, norway and France(?) we are using ',' as decimal separator and it always messes up when you convert a double to and from a string where the interface expects double values stored...
2
by: Denis | last post by:
Hi, I am trying to convert a double to a string. The problem the value of the double may vary and I need to always the exact value without the exponential and without rounding. Example: double...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.