gpt4 book ai didi

ruby-on-rails - 修剪字符尾随的零 n 轨

转载 作者:行者123 更新时间:2023-11-29 13:01:07 24 4
gpt4 key购买 nike

在我的 PgSQL 数据库中,我的列之一是“字符变化”。当我将 excel 文件中的数字保存到其中时,它会将 .0 添加到末尾。我该如何修剪它?

我试过 row[1].to_s.strip 但这并没有删除 .0。添加 to_i 也不起作用,因为某些值的格式为 45-8

最佳答案

你想为此使用 chomp:

row[1].chomp('.0')

引自docs :

Returns a new String with the given record separator removed from the end of str (if present).

关于ruby-on-rails - 修剪字符尾随的零 n 轨,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29821351/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com