去掉 。来自十进制红宝石

时间:2016-04-27 20:31:01

标签: ruby-on-rails ruby ruby-on-rails-4

我有一个十进制列10.00。我有两个价格:11.5010.00

我需要转换

1000加入11.50

1150加入{{1}}

我怎么能在控制器中做到这一点?

3 个答案:

答案 0 :(得分:6)

只需将数字乘以100,然后对结果执行to_i

f = 10.0
n = (f * 100).to_i

答案 1 :(得分:3)

如果它是一个字符串:

"10.00".gsub(".", "")

如果是十进制数

(10.00 * 100).to_i

答案 2 :(得分:0)

转字符串,替换点,转int

 cypress.json

{
  "reporter": "junit",
  "reporterOptions": {
    "mochaFile": "results/test-output-[hash].xml",
    "toConsole": true,
    "attachments": true
  }
}


  browserstack.json

{
    "auth": {...},
    "browsers": [...],

    "run_settings": {
      "cypress_config_file": "./cypress.json",
      "cypress_version": "6",
      "project_name": "FancyProjectName",
      "build_name": "Build no. 42",
      "parallels": "2",
      "npm_dependencies": {
        "typescript": "^4.2.4"
      }
    }
  }

打印 1056