Lucy Weatherford
Lucy Weatherford

Reputation: 5534

Variable data type and changes to it

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.

Upvotes: 1

Views: 487

Answers (2)

pierallard
pierallard

Reputation: 3371

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

Upvotes: 3

Fiona T
Fiona T

Reputation: 1929

Upvotes: 2

Related Questions