R
Robert TV
I would like to know if Perl has a function to correctly format a string of
numbers into currency format. I have a small subroutine that takes a number
and adds a tax amount. Below is the base:
$amount = 100;
$tax = 0.05 # 5% tax rate
$finaltotal = $amount * $tax;
$finaltotal = sprintf("%.02f",$finaltotal);
Sometimes when then $amount is a complex number such as 1423 I will get
several decimal places, and sprintf rounds to two decimal places. This is
good. But when the amount like simple as seen above, there are no cedimal
places, therefor sprintf doesnt have anything to round. I am trying to make
it so all $finaltotals have two decimal places, even if they are .00 or .90
etc. Can anyone help? TIA!
Robert
numbers into currency format. I have a small subroutine that takes a number
and adds a tax amount. Below is the base:
$amount = 100;
$tax = 0.05 # 5% tax rate
$finaltotal = $amount * $tax;
$finaltotal = sprintf("%.02f",$finaltotal);
Sometimes when then $amount is a complex number such as 1423 I will get
several decimal places, and sprintf rounds to two decimal places. This is
good. But when the amount like simple as seen above, there are no cedimal
places, therefor sprintf doesnt have anything to round. I am trying to make
it so all $finaltotals have two decimal places, even if they are .00 or .90
etc. Can anyone help? TIA!
Robert