472,371 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 7008


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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.