Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 06-11-04
morleymouse's Avatar
Super Member
 
Join Date: Aug 2003
Location: Costa Del Sheffield
Posts: 2,752
Thanks: 3
Thanked 10 Times in 6 Posts
morleymouse is an unknown quantity at this point
  php number manipulation

So I want to check / make sure the number the user enteres is in the format I want.

I can get it so that the number is an integer quite easily with

$new_number = intval("$old_number");

But say is there any way of making it a multiple of like 0.1 or 0.2 etc?

So it rounds up or down to the nearest tenth?

So I have it set to the nearest tenth and then the user enters 0.7, then it gets entered as 0.1. or 4.21 goes to 4.2 etc
__________________
Dan Morley
Alpharooms.com
daniel at alpharooms dot com - Hotels, Flights, Airport Transfers, Care Hire + More! sign up
My Blog | Cheap Holidays
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-11-04
Registered User
 
Join Date: Jun 2004
Location: Cambridge
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
PaulD is an unknown quantity at this point
Have look at the php.net documentation for round() http://uk.php.net/manual/en/function.round.php should do the trick.

Paul
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-11-04
morleymouse's Avatar
Super Member
 
Join Date: Aug 2003
Location: Costa Del Sheffield
Posts: 2,752
Thanks: 3
Thanked 10 Times in 6 Posts
morleymouse is an unknown quantity at this point
cheers paul, did receive help on this via PM.

round is now part of the solution
__________________
Dan Morley
Alpharooms.com
daniel at alpharooms dot com - Hotels, Flights, Airport Transfers, Care Hire + More! sign up
My Blog | Cheap Holidays
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-11-04
Paul Knapp's Avatar
Registered User
 
Join Date: Aug 2003
Location: Kent
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Paul Knapp is an unknown quantity at this point
Why not store the number as a standard floating point, and only display to the screen the rounded number?

<?

$num = 4.215;

printf("Your rounded number is %01.1f to the nearest tenth",$num);

?>

If you DO want to store the rounded number, I would think sprintf was a much more robust (and faster) way to do it.

<?

$num = 4.215;

$rounded = sprintf("%01.1f",$num);

echo "<b>$num</b> to the nearest tenth is <b>$rounded</b>.";

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7