string to single

jordi

New member
Joined
Jan 23, 2006
Messages
2
Programming Experience
Beginner
Hi,

I'm trying to convert a string value to a single number.
Considering the following:

dim a as string = "00.1851"
dim b as single = csng(a)

I get b= 1851.0 where I expected b= 0.1851.

Does anybody know the right way to do this?

Thanks a lot!

Jordi
 
In VB 2005 you can try the following :

VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Result [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Single
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Single[/COLOR][/SIZE][SIZE=2].TryParse(a, Result)
[/SIZE]

If string a is not a numeric value, Result will be set to 0.
 
Thanks guys,

I had a problem with my computer culture, because my O.S is spanish, so switching to english culture when program starts solved the problem.

Thanks fr replying,

Jordi
 
Back
Top