hi friends,
iam working on RoR code, i want to know how to find two digit precision for the numbers
a = 0.7
b = 5
thanks
hi friends,
iam working on RoR code, i want to know how to find two digit precision for the numbers
a = 0.7
b = 5
thanks
number_with_precision
. If you're looking to express them as currency, use number_to_currency
.
If you're looking to store those numbers and their precision in the database you should set up decimal fields.
add_column :table_name, :column_name, :decimal, :precision => 5, :scale => 2
Options for a decimal field:
With a decimal field you will never need the helper methods to limit the precision after the decimal place.
Always your standard
a = "%.2f" % 0.2
b = "%.2f" % 5
Outputs strings though, so you may need ("%.2f" % 0.2).to_i
or cast later (a.to_i
).