Did I find the right examples for you? yes no

All Samples(18)  |  Call(16)  |  Derive(0)  |  Import(2)
Scale val in the range [0, val_range-1] to an integer in the range 
[0, out_range-1].  This implementaton uses the "round-half-up" rounding 
method.

>>> "%x" % int_scale(0x7, 0x10, 0x10000)
'7777'
>>> "%x" % int_scale(0x5f, 0x100, 0x10)
'6'
>>> int_scale(2, 6, 101)
40(more...)

        def int_scale(val, val_range, out_range):
	"""
	Scale val in the range [0, val_range-1] to an integer in the range 
	[0, out_range-1].  This implementaton uses the "round-half-up" rounding 
	method.

	>>> "%x" % int_scale(0x7, 0x10, 0x10000)
	'7777'
	>>> "%x" % int_scale(0x5f, 0x100, 0x10)
	'6'
	>>> int_scale(2, 6, 101)
	40
	>>> int_scale(1, 3, 4)
	2
	"""
	num = int(val * (out_range-1) * 2 + (val_range-1))
	dem = ((val_range-1) * 2)
	# if num % dem == 0 then we are exactly half-way and have rounded up.
	return num / dem
        


src/c/c/ccx2-HEAD/src/ccx2/urwid/display_common.py   ccx2(Download)
import termios
 
from util import int_scale
import signals
 
# convert steps to values that will be used by string versions of the colors
# 1 hex digit for rgb and 0..100 for grayscale
_CUBE_STEPS_256_16 = [int_scale(n, 0x100, 0x10) for n in _CUBE_STEPS_256]
_GRAY_STEPS_256_101 = [int_scale(n, 0x100, 101) for n in _GRAY_STEPS_256]
_CUBE_STEPS_88_16 = [int_scale(n, 0x100, 0x10) for n in _CUBE_STEPS_88]
_GRAY_STEPS_88_101 = [int_scale(n, 0x100, 101) for n in _GRAY_STEPS_88]

src/r/e/reddit-cli-HEAD/urwid/display_common.py   reddit-cli(Download)
import termios
 
from util import int_scale
import signals
 
# convert steps to values that will be used by string versions of the colors
# 1 hex digit for rgb and 0..100 for grayscale
_CUBE_STEPS_256_16 = [int_scale(n, 0x100, 0x10) for n in _CUBE_STEPS_256]
_GRAY_STEPS_256_101 = [int_scale(n, 0x100, 101) for n in _GRAY_STEPS_256]
_CUBE_STEPS_88_16 = [int_scale(n, 0x100, 0x10) for n in _CUBE_STEPS_88]
_GRAY_STEPS_88_101 = [int_scale(n, 0x100, 101) for n in _GRAY_STEPS_88]