How can I convert a string to a number in Perl?

Anton picture Anton · Nov 14, 2008 · Viewed 276.1k times · Source

I have a string which holds a decimal value in it and I need to convert that string into a floating point variable. So an example of the string I have is "5.45" and I want a floating point equivalent so I can add .1 to it. I have searched around the internet, but I only see how to convert a string to an integer.

Answer

Alnitak picture Alnitak · Nov 14, 2008

You don't need to convert it at all:

% perl -e 'print "5.45" + 0.1;'
5.55