forked from fixin.me/fixin.me
Print multiplier in scientific notation
This commit is contained in:
@@ -99,4 +99,26 @@ module ApplicationHelper
|
||||
|
||||
send "#{type}_to", name, options, html_options
|
||||
end
|
||||
|
||||
# Converts value to HTML formatted scientific notation
|
||||
def scientifize(d)
|
||||
sign, coefficient, base, exponent = d.split
|
||||
return 'NaN' unless sign
|
||||
|
||||
result = (sign == -1 ? '-' : '')
|
||||
unless coefficient == '1' && sign == 1
|
||||
if coefficient.length > 1
|
||||
result += coefficient.insert(1, '.')
|
||||
elsif
|
||||
result += coefficient
|
||||
end
|
||||
if exponent != 1
|
||||
result += "×"
|
||||
end
|
||||
end
|
||||
if exponent != 1
|
||||
result += "10<sup>#{exponent-1}</sup>"
|
||||
end
|
||||
result.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user