Convert strings in numbers

Just starting out? Need help? Post your questions and find answers here.
Klaus_1963
User
User
Posts: 29
Joined: Wed Nov 25, 2009 9:37 am

Convert strings in numbers

Post by Klaus_1963 »

In C# I use Double.Parse("1e-234") to convert a string to a (very small or big) number, or Convert.ToString(1e-234) to convert a small double to string (and the result shown is not only "0". It is 1e-234 as it should be).

What are the corresponding commands in PB, which works correctly? StrD and Val are not useable for small or big values...

Thanks, Klaus
PureBasic 4.72 LTS - Windows / MacOS / Linux / strong coffee / stronger coffee / Coffee intravenously...
User avatar
TI-994A
Addict
Addict
Posts: 2778
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Convert strings in numbers

Post by TI-994A »

Klaus_1963 wrote:...Double.Parse("1e-234") to convert a string to a (very small or big) number, or Convert.ToString(1e-234) to convert a small double to string
Hello Klaus_1963. I believe that PureBasic's not able to handle such huge or small numbers. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
TassyJim
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: Convert strings in numbers

Post by TassyJim »

You might have problems displaying the result, but valD does work.

Code: Select all

firstvalueastring.s ="1e234"
firstvalue.d=ValD(firstvalueastring)
secondvalueastring.s ="1.5e230"
secondvalue.d=ValD(secondvalueastring)
result.d=firstvalue/secondvalue
Debug result
I don't think there is a command for displaying numbers in scientific notation (unfortunately)

Doing a search for scientific notation and I found this:

http://www.purebasic.fr/english/viewtop ... c+notation

Jim
Klaus_1963
User
User
Posts: 29
Joined: Wed Nov 25, 2009 9:37 am

Re: Convert strings in numbers

Post by Klaus_1963 »

Thanks a lot

Unfortunately, it's not a solution for my problem.

@TassyJim: if you debug a large number e.g. 1e+68 and you like to check it with a debug output, its not possible. Only if you count the zeros ;-)

What a pity! Otherwise PB could be used for easy programming scientific applications...

Of course, there is code available to view very small numbers. But it would be much more elegant, if I can use e.g. StrD etc. to view the number in a label field, and the debug output to check the number quickly.

Every other pl I use know such a command with works correctly...

Would be great, if Fred implement this...

Klaus
PureBasic 4.72 LTS - Windows / MacOS / Linux / strong coffee / stronger coffee / Coffee intravenously...
Post Reply