Jun 28, 2001 #1 rcsen Programmer Jan 11, 2001 51 US Hi, I would like to convert a string variable which contains fraction to a numeric value, say, 125 1/2 to 125.50 Could you please suggest a solution? Thanks in Advance. -RCSEN.
Hi, I would like to convert a string variable which contains fraction to a numeric value, say, 125 1/2 to 125.50 Could you please suggest a solution? Thanks in Advance. -RCSEN.
Jun 29, 2001 1 #2 latch Programmer Jun 26, 2001 89 DE Assuming blank space is your delimiter, $number = "125 1/2"; ($pre,$post)=split (/ /,$number); $result=$pre + eval ( $post ); HTH regards CM Upvote 0 Downvote
Assuming blank space is your delimiter, $number = "125 1/2"; ($pre,$post)=split (/ /,$number); $result=$pre + eval ( $post ); HTH regards CM
Jun 29, 2001 #3 tsdragon Programmer Dec 18, 2000 5,133 US Good answer! Tracy Dryden tracy@bydisn.com Meddle not in the affairs of dragons, For you are crunchy, and good with mustard. Upvote 0 Downvote
Good answer! Tracy Dryden tracy@bydisn.com Meddle not in the affairs of dragons, For you are crunchy, and good with mustard.
Jun 29, 2001 #4 tsdragon Programmer Dec 18, 2000 5,133 US BTW, if you want to make sure the number has only two decimals, like your example, you can use sprintf: Code: $result = sprintf("%.2f", $result); Tracy Dryden tracy@bydisn.com Meddle not in the affairs of dragons, For you are crunchy, and good with mustard. Upvote 0 Downvote
BTW, if you want to make sure the number has only two decimals, like your example, you can use sprintf: Code: $result = sprintf("%.2f", $result); Tracy Dryden tracy@bydisn.com Meddle not in the affairs of dragons, For you are crunchy, and good with mustard.
Jun 29, 2001 Thread starter #5 rcsen Programmer Jan 11, 2001 51 US Hi latch and Tracy, Thank you very much for the help. -RCSEN. Upvote 0 Downvote