[SOLVED] Need to Round Off some numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

Need to Round Off some numbers

Post by irishmike2004 »

I have these numbers with decimals that I need to round off and not being a good math guy, hoped you guys had some suggestions.

The following are the variables and then the number they yeild.

Code: Select all

// barometer conversions
	
	$millibars = (33.8639 * $barPressure);
	$millimeters = (25.4 * $barPressure);
	
	// wind conversions
	
	$windkmh = (1.609344 * $windSpeed);
	$windKnots = (.868976 * $windSpeed);
the current value of $barPressure is 29.98
and of $windSpeed is 16 (in MPH)

The above converts them to metric equivalents.

on the barometer I need to round off to 2 decimal spots and on the windspeed would prefer to round off to 1 decimal spot.

here is the output:

Barometer in mb = 1015.239722 => rounded to 1015.24 ideally
Barometer in mm = 761.492 => rounded to 761.5
Wind KMH = 25.749504 => rounded to 25.7
Wind Knots = 13.903616 => rounded to 13.9

Help is appreciated.

Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]round()[/php_man]
irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

Post by irishmike2004 »

Hi Guys found it!

used the round() function worked great. This one solved!
Post Reply