Trim a trailing .0

前端 未结 4 1069
我在风中等你
我在风中等你 2021-02-19 01:02

I have an Excel column containing part numbers. Here is a sample

\"\"

As you can see, it can be many differ

4条回答
  •  我在风中等你
    2021-02-19 02:03

    For those using Rails, ActionView has the number_with_precision method that takes a strip_insignificant_zeros: true argument to handle this.

    number_with_precision(13.00, precision: 2,  strip_insignificant_zeros: true)
    # => 13
    number_with_precision(13.25, precision: 2,  strip_insignificant_zeros: true)
    # => 13.25
    

    See the number_with_precision documentation for more information.

提交回复
热议问题