Jump to content


Photo

Checking to see if something is a multiple of 25?


  • Please log in to reply
2 replies to this topic

#1 ChambeRFienD

ChambeRFienD
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 29 August 2006 - 09:09 PM

Hello, I'd like to write a script to only accept numbers that are multiples of 25, starting at 100 and ending at 50,000...

So if they select something lower than 100 they get an error, something higher than 50,000 they get an error, and if they enter something like 101, it will round it to 125.. I'm sure I could do this with a select(), but it would be an extreme pain to do that for every 25 all the way up to 50,000...

To clear things up:

If they enter 101 in the field, it will round it to 125. If they ender 24,142 it will round to 24,150.. Anyone know a way to do this?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 29 August 2006 - 09:18 PM

<?php
if ($thing><100) {
   echo "an error";
} else {
   $newthing = 25*ceil($thing/25); // result
   .... any other code ...
}
?>

Legend has it that reading the manual never killed anyone.
My site

#3 ChambeRFienD

ChambeRFienD
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 29 August 2006 - 09:20 PM

<?php
if ($thing><100) {
   echo "an error";
} else {
   $newthing = 25*ceil($thing/25); // result
   .... any other code ...
}
?>


Thanks much!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users