logo
  • 教程列表
  • SO官方文档
  • 转换(类型转换)
    • 转换到浮点型
    • 转换为字符串
    • 转换为整数
    • 浮点数和整数
  1. StackOverflow 文档
  2. Ruby Language 教程
  3. 转换(类型转换)
  4. 转换到浮点型

转换到浮点型

Created: November-22, 2018

"123.50".to_f   #=> 123.5
Float("123.50") #=> 123.5

但是,当字符串不是有效的 Float 时,存在差异:

"something".to_f   #=> 0.0
Float("something") # ArgumentError: invalid value for Float(): "something"
  • 转换为字符串
  • 转换(类型转换)

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明