473,782 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(string Val)
Msgbox (doubleVal) will return 101.01

but......
Dim stringVal As String = "101.00"
Dim doubleVal As Double
doubleVal = System.Convert. ToDouble(string Val)
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 6632
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.c om...

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(string Val)
Msgbox (doubleVal) will return 101.01

but......
Dim stringVal As String = "101.00"
Dim doubleVal As Double
doubleVal = System.Convert. ToDouble(string Val)
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(string Val)
Msgbox (doubleVal) will return 101.01

but......
Dim stringVal As String = "101.00"
Dim doubleVal As Double
doubleVal = System.Convert. ToDouble(string Val)
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
3541
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 configuration
10
19668
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 Convert.ToDouble(..) accept both comma and period notations for representing numbers?
3
688
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 formats like: 37.439351 2.00000e+02 How can i do it most easily ?
2
1648
by: ORC | last post by:
What is the difference between: Convert.ToDouble(Int16number); and: (double)Int16number; ? and which is the fastest? Thanks Ole
4
11114
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 like cint(anInt) and cType(anInt, System.Int32) but I checked with ildasm) - if I didn't made a mistake. So when to use which syntax? Is there any performance penalty when using the one over the other or does anybody knows any differences? '...
3
8749
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; this produced an error
2
2335
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 (float)Convert.ToDouble(xml.value) (which in this case is "8.25"). I am wondering if someone could tell me how the command is changed in 2003 or 2005 as it stops here.
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6735
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
5378
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
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.