0 Replies - 1659 Views - Last Post: 22 January 2020 - 07:56 AM

#1 Aisaac23   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 28-April 19

Always round up

Posted 22 January 2020 - 07:56 AM

def roundAlwaysUp( toRound, end = 10 ):
	""" 
	This snippet will round-up any given integer or float, to at least 10 or to the highest multiple of 10.
	You can pass an unsigned/positive integer as the "end" argument if you want the number to be rounded to at least a multiple of "end".
	Returned value will always be an integer.
	"""
	end = abs( int( end ) )
	if end == 0:
		end = 10
	times = toRound/end
	if times >= 0:
		times = times + 1
	else:
		times = times - 1
	return ( int( times ) )*end;

#Tests:
#print( roundAlwaysUp(300, .000000075) ); #expected output: 310
#print( roundAlwaysUp(-24748243.8987, 500) ); #expected output: -24748500
#print( roundAlwaysUp(24748243.8987) ); #expected output: -24748250
#print( roundAlwaysUp(0) ); #expected output: 10
#print( roundAlwaysUp(300, 0) ); #expected output: 310



Is This A Good Question/Topic? 0
  • +

Page 1 of 1