Am 04.12.2012 21:00, schrieb sto.mar / web.de:
> Am 04.12.2012 19:31, schrieb Alexander G.:
>> Hi Please advice how to extract exact number from string:
>>
>> $5.99 /LB
>>
>> I need to get 5.99 as float number
>>
>> Thank you in advance
>>
>
> Using float for currency is a bad idea.
>
> [13] pry(main)> 1.11 - 0.12
> => 0.9900000000000001

/\$(?<dollars>\d+)\.(?<cents>\d+)/ =~ "$5.99 /LB"
amount_in_cent = 100 * dollars.to_i + cents.to_i  # => 599

(see RegExp documentation)


-- 
<https://github.com/stomar/>