[英]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). 我试图找出某个变量的数据类型(它是RoR应用程序中db中的一列)。 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. 我想将其格式化为带有2个小数的数字,但是我想首先找出它是字符串还是整数。
For the format of your 2-decimals number, see this post What is the best method of handling currency/money? 有关2进制数字的格式,请参阅此文章。处理货币/金钱的最佳方法是什么?
The best way to do is to not change it, and register it directly with rails. 最好的方法是不要更改它,而直接在rails中注册它。
If you have to change a string to a 2-decimal number, create a migration with 如果必须将字符串更改为2进制数,请使用
my_decimal_number
add_column my_decimal_number
my_string_number
to my_decimal_number
执行数据库查询以将表从my_string_number
更新为my_decimal_number
my_string_number
删除my_string_number
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.