Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 11:51 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: April 22nd, 2007, 1:10 am 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Since we are discussing undocumented Opusscript :-)
You can use parseInt() instead of number() to convert a string representation of a number to a number, even with a base other than 10.
ie, have two numbers in string form.

str1="22"
str2="44"

str2Num1=parseInt(str1,10) // 10 is the usual number base
str2Num2=parseInt(str2,10)

// now you can add them

ans = str2Num1 + str2Num2

You can also use parseInt() to extract a number from a string for further processing.
parseInt("43.45 kg") will return 43.

If you want the whole number returned, then use the similar function parseFloat().
parseFloat("43.45 kg") will return 43.45

You can also convert from various bases to base 10
//Hex to Decimal conversion
parseInt("3A8", 16);// returns 936

//Binary to Decimal conversion
parseInt("1011", 2) // returns 11

cheers
Paul


For this message Paul has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Majestic-12 [Bot] and 65 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group