简体   繁体   English

可变数据类型及其更改

[英]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个小数的数字,但是我想首先找出它是字符串还是整数。

  • 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? 最好的方法是什么-在CSS中更改它? in js? 在js中? in the variable type? 在变量类型?

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进制数,请使用

  • add_column my_decimal_number add_column my_decimal_number
  • execute an DB query to update your table from my_string_number to my_decimal_number 执行数据库查询以将表从my_string_number更新为my_decimal_number
  • deletes my_string_number 删除my_string_number

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM