Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

round 2

Status
Not open for further replies.

kzn

MIS
Jan 28, 2005
209
GB
Hi

Any help appreciated thank you.
I have the following problem:

$number = 6478;

$value = $number/1000;

I need to round $value to the nearest 0.25 and I have no idea how to do it. In the above example this would round to 6.5.

I need it to do the following if
$number = 6695; result would be 6.75

or
$number = 6530; result would be 6.5

Any help or pointers appreciated thank you
 
Hi

I wound use this :
PHP:
[b]function[/b] [COLOR=darkgoldenrod]kznround[/color][teal]([/teal][navy]$what[/navy][teal])[/teal]
[teal]{[/teal]
  [b]return[/b] [COLOR=darkgoldenrod]round[/color][teal]([/teal][navy]$what[/navy][teal]/[/teal][purple]250[/purple][teal])/[/teal][purple]4[/purple][teal];[/teal]
[teal]}[/teal]
For which this :
Code:
[b]foreach[/b] [teal]([/teal][b]array[/b][teal]([/teal][purple]6478[/purple][teal],[/teal][purple]6695[/purple][teal],[/teal][purple]6530[/purple][teal])[/teal] [b]as[/b] [navy]$one[/navy][teal])[/teal]
  [b]echo[/b] [green][i]"$one -> "[/i][/green][teal],[/teal][COLOR=darkgoldenrod]kznround[/color][teal]([/teal][navy]$one[/navy][teal]),[/teal][green][i]"\n"[/i][/green][teal];[/teal]
Gives this :
Code:
6478 -> 6.5
6695 -> 6.75
6530 -> 6.5

Feherke.
 
generically, isn't the way of doing this something like:

Code:
round ($number/$roundto) * $roundto;
 
Hi feherke

Thanks for your answer it works perfectly.Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top