Gossamer Forum
Home : Products : DBMan : Installation :

How do you truncate decimal to the tenths?

Quote Reply
How do you truncate decimal to the tenths?
I finally got what I wanted with my rates table, but I have trialing decimal =(

I wanted to know if you could help me round them to the tenths place.

Here is my code so far:

my $annual_rate = $rec{'Rate'} * 10.00 + 75.00;
my $semi_annual_rate = $annual_rate * .510;
my $quarterly_rate = $annual_rate * .295;
my $monthly_rate = $annual_rate * .087;
print qq|
<TABLE WIDTH="400" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
<TR><TD ALIGN="Left" VALIGN="TOP" WIDTH="150"><$font>Your Rate is</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <$font>$rec{'Rate'}</font></TD></TR>
<TR><TD ALIGN="Left" VALIGN="TOP" WIDTH="150"><$font>Annual Fee</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <$font>\$</font> <$font>$annual_rate</font></TD></TR>
<TR><TD ALIGN="Left" VALIGN="TOP" WIDTH="150"><$font>Semi-Annual Fee</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <$font>\$</font> <$font>$semi_annual_rate</font></TD></TR>
<TR><TD ALIGN="Left" VALIGN="TOP" WIDTH="150"><$font>Quarterly Fee</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <$font>\$</font> <$font>$quarterly_rate</font></TD></TR>
<TR><TD ALIGN="Left" VALIGN="TOP" WIDTH="150"><$font>Monthly Fee</FONT></TD>
<TD VALIGN="TOP" WIDTH="475"> <$font>\$</font> <$font>$monthly_rate</font></TD></TR>
</TABLE>

I thank you again gentleman for help me along with my work.

Quote Reply
Re: How do you truncate decimal to the tenths? In reply to
I'm not exactly sure, but see if this works:

my $annual_rate = sprintf("%.2f", $annual_rate);