How do I convert a string to number in Perl?
Example:
$str = '10.0500000';
$number = $str * 1; # 10.05
Is there another standard way to get 10.05 from '10.0500000' instead of multiplying with one?
edit 2020: Answer is wrong, see comment below. I am not permitted to delete an accepted answer.
I am answering the literal question. Perhaps you want to format the number for display.
Both expressions
sprintf '%.2f', '10.0500000'
sprintf '%.2f', 10.0500000
return the string 10.05
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With