473,387 Members | 1,585 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,387 software developers and data experts.

System.Convert.ToDouble


In VB.NET, when I use System.Convert.ToDouble(string Val) to convert a string
variable to double variable, I got something interesting:

Dim stringVal As String = "101.01"
Dim doubleVal As Double
doubleVal = System.Convert.ToDouble(stringVal)
Msgbox (doubleVal) will return 101.01

but......
Dim stringVal As String = "101.00"
Dim doubleVal As Double
doubleVal = System.Convert.ToDouble(stringVal)
Msgbox (doubleVal) will return 101

where is the ".00" ?
Should I get 101.00 instead of 101?

Did I missed something here?
TIA
Nov 21 '05 #1
2 6580
Why do you think you should have the 00? 101.00=101. And 101 happens to be
what happens when the tostring method is called in this case (which is
called implicitly, since you are not doing it explicitly).

If you want the decimal places to always show up, you should use custom
format strings to ensure that the formatting to your liking - otherwise you
will get default behavior. But I am not sure why you feel there is something
wrong with the default behavior.

"Jason" <ja***@hotmail.com> wrote in message
news:t9********************************@4ax.com...

In VB.NET, when I use System.Convert.ToDouble(string Val) to convert a string variable to double variable, I got something interesting:

Dim stringVal As String = "101.01"
Dim doubleVal As Double
doubleVal = System.Convert.ToDouble(stringVal)
Msgbox (doubleVal) will return 101.01

but......
Dim stringVal As String = "101.00"
Dim doubleVal As Double
doubleVal = System.Convert.ToDouble(stringVal)
Msgbox (doubleVal) will return 101

where is the ".00" ?
Should I get 101.00 instead of 101?

Did I missed something here?
TIA

Nov 21 '05 #2
* Jason <ja***@hotmail.com> scripsit:
In VB.NET, when I use System.Convert.ToDouble(string Val) to convert a string
variable to double variable, I got something interesting:

Dim stringVal As String = "101.01"
Dim doubleVal As Double
doubleVal = System.Convert.ToDouble(stringVal)
Msgbox (doubleVal) will return 101.01

but......
Dim stringVal As String = "101.00"
Dim doubleVal As Double
doubleVal = System.Convert.ToDouble(stringVal)
Msgbox (doubleVal) will return 101

where is the ".00" ?
Should I get 101.00 instead of 101?


The variable is stored in IEEE floating point format after parsing the
string. 'MsgBox' will call 'ToString' on the variable implicitly and
this will convert the variable to a string. You can specify the format
used to format the variable's value as a string in an overloaded version
of the 'ToString' method.

I suggest to turn on 'Option Strict' by placing 'Option Strict On' on
top of your source file.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #3

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

Similar topics

4
by: Irepan | last post by:
does anybody know how to change the global IFormatProvider of my project so everycall to Convert.ToDouble on it uses this format provider instead of the one the one on the computer's regional...
10
by: | last post by:
Hey I am calling Convert.ToDouble(someString); But this double can have to ways or representing doubles dependant on the locale, it can be 1.0 or 1,0 Is there a way to make...
3
by: user | last post by:
Hello i have problems with this function, always thru exception for all data, for example: Convert.ToDouble("545.0"). Why ? I want to convert string data in different format into double, i have...
2
by: ORC | last post by:
What is the difference between: Convert.ToDouble(Int16number); and: (double)Int16number; ? and which is the fastest? Thanks Ole
4
by: Daniel Walzenbach | last post by:
Hi, I wonder if somebody could explain me the difference between Double.Parse and Convert.ToDouble. If I'm not mistaken they are implemented differently (I though for a moment they might be the same...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
2
by: trondhuso | last post by:
Hi group, I've found some code that I want to use in a project that I am working on, but the code is for c# .net and not 2003 or 2005 that I have available. In this code the program yells on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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.