Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Roundup to the nearest 5?


  • Please log in to reply
5 replies to this topic
Bobendren
  • Members
  • 9 posts
  • Last active: Sep 07 2010 09:07 AM
  • Joined: 30 Oct 2009
How would I round up to the nearest 5?

So 100 would stay 100,
101, 102, 103, 104 would become 105,
105 would stay 105,
106, 107, 108, 109 would become 110
and 110 would stay 110.

Carcophan
  • Members
  • 1578 posts
  • Last active: Nov 27 2013 06:46 PM
  • Joined: 24 Dec 2008

Round(Number [, N]): If N is omitted or 0, Number is rounded to the nearest integer. If N is positive number, Number is rounded to N decimal places. If N is negative, Number is rounded by N digits to the left of the decimal point. For example, Round(345, -1) is 350 and Round (345, -2) is 300. Unlike Transform Round, the result has no .000 suffix whenever N is omitted or less than 1. In v1.0.44.01+, a value of N greater than zero displays exactly N decimal places rather than obeying SetFormat. To avoid this, perform another math operation on Round()'s return value; for example: Round(3.333, 1)+0.

:?:


Nevermind, this wouldn't keep your '105' at 105, but I left it up instead of ereasing it incase it was still of value to you.

a_h_k
  • Members
  • 681 posts
  • Last active: Oct 27 2012 04:50 AM
  • Joined: 02 Feb 2008
Something like this should do the trick..

rem := Mod(num, 5)
rnd_amount := 5 - rem
If (rnd_amount=5)
  rnd_amount = 0	;so 100 stays at 100
rounded := num + rnd_amount


MasterFocus
  • Moderators
  • 4322 posts
  • Last active: Feb 05 2014 06:15 PM
  • Joined: 08 Apr 2009
[color=red]Rounded[/color] := [color=darkred]Original[/color] + ( 5 - Mod([color=darkred]Original[/color],5) )

; OR

[color=violet]Number[/color] += ( 5 - Mod([color=violet]Number[/color],5) )


a_h_k
  • Members
  • 681 posts
  • Last active: Oct 27 2012 04:50 AM
  • Joined: 02 Feb 2008
Well done MasterFocus! :)

Bobendren
  • Members
  • 9 posts
  • Last active: Sep 07 2010 09:07 AM
  • Joined: 30 Oct 2009
Cool, thanks guys :)