1

I am trying to find out a data type of a certain variable (it is a column in a db in RoR application). I would like to format it as a number with 2 decimals, but I want to first find out if it is a string or an integer.

  • How can I find out?
  • How can I change it? (And do I need to)
  • How do I format it to two decimals, whatever the original is?
  • What is the best way to go about this - change it in css? in js? in the variable type?
Lucy Weatherford
  • 5,452
  • 16
  • 50
  • 76

2 Answers2

3

For the format of your 2-decimals number, see this post What is the best method of handling currency/money?

The best way to do is to not change it, and register it directly with rails.

If you have to change a string to a 2-decimal number, create a migration with

  • add_column my_decimal_number
  • execute an DB query to update your table from my_string_number to my_decimal_number
  • deletes my_string_number
Community
  • 1
  • 1
pierallard
  • 3,326
  • 3
  • 21
  • 48
2
Fiona T
  • 1,921
  • 1
  • 15
  • 18