HighTechTalks DotNet Forums  

which method i can use for converting a string to a number?

Dotnet Scripting microsoft.public.dotnet.scripting


Discuss which method i can use for converting a string to a number? in the Dotnet Scripting forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Alice
 
Posts: n/a

Default which method i can use for converting a string to a number? - 08-16-2005 , 12:08 AM






which method i can use for converting a string to a number?

x10000 thanks

Reply With Quote
  #2  
Old   
Mona
 
Posts: n/a

Default Re: which method i can use for converting a string to a number? - 08-17-2005 , 04:50 PM






Hi Alice,

We can use an implicit type conversion that may fail at runtime. This means
that some string values do not have an obvious analogue as a number or
Boolean.



Using explicit type conversions, which allow for lossy conversions, makes
code more reliable and much less likely to fail at runtime.



Hope this helps.



Best Regards,

Mona [Grapecity]





"Alice" <Alice (AT) discussions (DOT) microsoft.com> wrote

Quote:
which method i can use for converting a string to a number?

x10000 thanks



Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default Re: which method i can use for converting a string to a number? - 08-30-2005 , 06:25 PM



Alice,

I had problems with the conversions, too. Here is a code snippet of my
solution: ( I am reading power data from an instrument)

double m_dTemp, m_dCh1LastPower; //

// This bypasses conversion error that shows up,
// Error is on return value of "" (Empty sting)
if ( Double.TryParse(strReading,
System.Globalization.NumberStyles.Float,
null, out m_dTemp) )
{ // True on successful conversion, so use it

m_dCh1LastPower = m_dTemp;
// To modify and return to string
m_dCh1LastPower = m_dCh1LastPower * 1000;
String sFormatter = "#0.00";
string txtNew = m_dCh1LastPower.ToString(sFormatter)
}



Mona wrote:
Quote:
Hi Alice,

We can use an implicit type conversion that may fail at runtime. This means
that some string values do not have an obvious analogue as a number or
Boolean.



Using explicit type conversions, which allow for lossy conversions, makes
code more reliable and much less likely to fail at runtime.



Hope this helps.



Best Regards,

Mona [Grapecity]





"Alice" <Alice (AT) discussions (DOT) microsoft.com> wrote in message
news:AF35175C-22BB-4E1B-A1D1-83DFA0FFD88B (AT) microsoft (DOT) com...
which method i can use for converting a string to a number?

x10000 thanks


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.