473,769 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert double to decimal without rounding

In the example below, the 'convert.ToDeci mal' 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.40002441406 25
dcml = Convert.ToDecim al(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 7163


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.40002441406 2 - 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 "IDontWantItRou nded" argument
passed in to the 'convert.todeci mal'.....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
2315
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
16549
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 want the result of shortVal = 3000 and store as short instead of double
1
1086
by: | last post by:
eg. "19.121" to 19.12 decimal eg. "12.567 " to 12.56 decimal
2
3153
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
16490
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
7520
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. sprintf (and its brothers) 3. any nonstandard C/C++ functions
1
4079
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 as string is using '.' What parameter shall I use in double.ToString() to ensure that the outputstring always are using '.' as separator without thousand sep, and what parameter shall I use to convert double to Double.Parse() or...
2
2223
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.00000000000000000000023 should be string 0.00000000000000000000023 and not 0.00 or 2.3-E24 I tried it with Console.WriteLine(dd.ToString("X", CultureInfo.InvariantCulture))
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
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.