Welcome to WebmasterWorld Guest from 54.167.250.64

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

# Newbie trying to learn

#### I Will Make It

10:17 pm on Feb 27, 2014 (gmt 0)

#### Full Member

joined:Jan 31, 2006
posts: 305

Hi!

I'm trying to learn some easy php.

Right now I would like to understand how I can take a number, ex: 42.5 and round it up or down to the closest number that ends on 9.

As in: 42.5 would be 39
but 47 would be 49

#### lucy24

10:44 pm on Feb 27, 2014 (gmt 0)

#### Senior Member from US

joined:Apr 9, 2011
posts:14157

Which direction do you want 44 to go?

:: thinking ::

Add 1, divide by 10, round to an integer.

#### I Will Make It

10:48 pm on Feb 27, 2014 (gmt 0)

#### Full Member

joined:Jan 31, 2006
posts: 305

I didn't think of that scenario ;) But up :)
I'm making a small code that takes the cost price from my supplier, and converts into the saleprice on my webshop :)

Thank you for your quick response!

#### LifeinAsia

12:16 am on Feb 28, 2014 (gmt 0)

#### Moderator from US

joined:Dec 10, 2005
posts:5702

add 1, divide by 10, round to an integer, multiply by 10, subtract 1. :)

#### lucy24

3:00 am on Feb 28, 2014 (gmt 0)

#### Senior Member from US

joined:Apr 9, 2011
posts:14157

"Having reduced the problem to a previously solved one, the mathematician went back to sleep."
:)

#### I Will Make It

6:28 pm on Feb 28, 2014 (gmt 0)

#### Full Member

joined:Jan 31, 2006
posts: 305