app/controllers/anoubis/data/convert.rb
##
# Format a number with grouped thousands
# @param number [Float] The number being formatted.
# @param precision [Integer] Sets the number of decimal points.
# @param point [Char] Sets the separator for the decimal point.
# @param separator [Char] Sets the thousands separator.
# @return [String] A formatted version of number.
Format a number with grouped thousands
Format a number with grouped thousands
def number_format(number, precision = 2, point = ',', separator = '')
        val = sprintf('%.'+precision.to_s+'f', number.round(precision)).to_s
        if separator != '' && number >= 1000
          whole_part, decimal_part = val.split('.')
          val = [whole_part.gsub(/(\d)(?=\d{3}+$)/, '\1'+separator), decimal_part].compact.join(point)
        else
          val = val.gsub('.', point)
        end
        val
      end
def number_format ( number , precision = 2 , point = ',' , separator = '' ) val = sprintf ( '%.' + precision . to_s + 'f' , number . round ( precision ) ) . to_s if separator != '' && number >= 1000 whole_part , decimal_part = val . split ( '.' ) val = [ whole_part . gsub ( / ( \d )(?= \d {3}+$) / , '\1' + separator ) , decimal_part ] . compact . join ( point ) else val = val . gsub ( '.' , point ) end val end
Format a number with grouped thousands
Format a number with grouped thousands
A formatted version of number.
A formatted version of number .
String
number
The number being formatted.
The number being formatted .
precision
Sets the number of decimal points.
Sets the number of decimal points .
point
Sets the separator for the decimal point.
Sets the separator for the decimal point .
separator
Sets the thousands separator.
Sets the thousands separator .