Back to SDS/2 Parametric Scripts
## round_length.py Version 1.02 (
## Copyright (c) 2007 Bruce Vaughan, BV
Detailing & Design, Inc.
## All rights reserved.
##
## Version 1.02 -
Added function round_length_near()
#################################################################
from param import dim
import math
## Function
definition - returns a float rounded down to the previous 'increment'
def round_length_last(length,
increment="1/16"):
if increment ==
"0":
return length
return float(math.floor(length/dim(increment)) * dim(increment))
## Function
definition - returns a float rounded up to the next 'increment'
def round_length_next(length,
increment="1/16"):
if increment ==
"0":
return length
return float(math.ceil(length/dim(increment)) * dim(increment))
## Function
definition - returns a float rounded to the nearest 'increment'
def round_length_near(length,
increment="1/16"):
if increment ==
"0":
return length
return
round(length/dim(increment)) * dim(increment)
def test_round():
print round_length_last(155.4663, "1/4")
print round_length_next(155.4663, "1/4")
print round_length_near(0.15+.02, "1/16")
## end test_round()
#########################################################
if __name__ == '__main__':
try:
test_round()
finally: