|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with rounding to 2 decimal places
Hi
I got this script which works out the price of hosting per year, what i would like it to do is work it out by per month so what it did was added this line: Code:
$m_price = $y_price / 12; And i think it did work it out for monthly price, the thing is it wrote it as 6.025 and i was wondering is there anyway to round this to 2 decimal places so it either equals 6.03 or 6.02 The script is located at http://www.sthost.com/cgi-bin/custom.cgi Also it somtimes works prices out as 1.2 instead of 1.20 so is there anyway of adding 0 onto it if it is only 1.2 Thanks. |
|
#2
|
||||
|
||||
|
Search your perl documentation, or do a google search for "printf" or "sprintf". They are your friends in this case.
|
|
#3
|
|||
|
|||
|
Hi
Ok thanks i'll have a look |
|
#4
|
|||
|
|||
|
Hi
I found something at http://www.perlmonks.org/index.pl?node=Using%20(s)printf()&lastnode_id=954 and tried it out and it works so thanks, just got to put it into the script now. Thanks |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Help with rounding to 2 decimal places |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|