56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/origen/core_ext/numeric.rb', line 56
def as_units(units)
if abs >= 1_000_000_000_000_000
"#{self / 1_000_000_000_000_000.0}P#{units}"
elsif abs >= 1_000_000_000_000
"#{self / 1_000_000_000_000.0}T#{units}"
elsif abs >= 1_000_000_000
"#{self / 1_000_000_000.0}G#{units}"
elsif abs >= 1_000_000
"#{self / 1_000_000.0}M#{units}"
elsif abs >= 1_000
"#{self / 1_000.0}k#{units}"
elsif abs >= 1
"#{self}#{units}"
elsif abs >= 1e-3
"#{self * 1_000}m#{units}"
elsif abs >= 1e-6
"#{self * 1_000_000}u#{units}"
elsif abs >= 1e-9
"#{self * 1_000_000_000}n#{units}"
elsif abs >= 1e-12
"#{self * 1_000_000_000_000}p#{units}"
elsif abs >= 1e-15
"#{self * 1_000_000_000_000_000}a#{units}"
else
"%.3e#{units}" % self
end
end
|