【问题标题】:Convert number in scientific notation string to float with limited C-like library使用有限的类 C 库将科学计数法字符串中的数字转换为浮点数
【发布时间】:2018-09-18 08:50:51
【问题描述】:

我正在用 CAPL(基于 C 并减去一些概念)编写一个程序,将包含以科学计数法显示的数字的字符串转换为浮点数(严格来说不需要是浮点数,但我认为它合适的类型)。例如:

-7.68000000E-06 应转换为 -0.00000768

我已经四处寻找这个,atof() 出现了很多,但是 CAPL 不支持这个,所以我不能使用它。

CAPL 不支持的其他 C 概念列表:

更新:感谢大家的帮助。 M. Spiller's answer 被证明是最简单的解决方案。我已经接受了这个答案。

【问题讨论】:

  • strtof 是否可用(来自标准库)?
  • CAPL 支持floatdouble 类型吗?
  • 附带说明,像-7.68000000E-06 这样的文字实际上已经是有效的C。使用strtod
  • 我猜你可以使用strtod 作为答案here

标签: c type-conversion scientific-notation capl


【解决方案1】:

在 CAPL 中,该函数称为 atodbl,其签名与 C 的 atof 相同。

【讨论】:

    猜你喜欢
    • 2014-07-01
    • 1970-01-01
    • 2010-09-09
    • 2020-06-10
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多