Decimal number in string to float conversion

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Decimal number in string to float conversion

Post by RadioT » Sat Nov 08, 2008 5:47 pm

Hello,

There are a number of nice float-to-string conversions, but how about the other way?

Let's say I'm converting a string of 123.456 to a float.

When it's always the same number of characters in front of the decimal, I can use the mid function, such as when pulling the 2 leading characters from the GPS time string to get the hour:

GPS_hour = StrToDec(Mid(GMT_time,0,2))

This works because even when there is one significant digit, since it's padded with a leading 0. So using place works in this case.

But when the leading numbers vary, I can build a loop to find the decimal, then assign each number to a float by dividing by the place (4/10, then 5/100, etc).

Is there a function that can do that already a part of SF? Or a more efficient way to do this?

Thanks,

de Tom

Post Reply