【问题标题】:How to convert a floating point value in exponential form to dot notation? [duplicate]如何将指数形式的浮点值转换为点符号? [复制]
【发布时间】:2010-08-29 17:41:15
【问题描述】:

可能重复:
Prevent scientific notation in ostream when using << with double

计算后我得到 1e-1 作为结果,如何将结果从指数转换为点表示法,即 0.1 ?为什么会自动转换成指数符号!!

【问题讨论】:

    标签: c++ oracle floating-point


    【解决方案1】:

    您可以使用fixed I/O 操纵器强制以定点表示法打印数字:

    double d = 42.0;
    std::cout << std::fixed << d;
    

    std::scientific 则相反:它强制以科学计数法打印数字)

    【讨论】:

    • 我想将值保存为双倍!
    • @yesraaj:你什么意思? 42.0 是 42.0,您如何格式化它以进行打印对存储的值没有影响。
    • 我将值保存到数据库中,并在其中使用双精度转换为 Oracle 中适当的 NUMBER 类型。
    • @yesraaj:那么问题出在 oracle 上,而不是 C++
    【解决方案2】:

    Oracle(通常)不处理二进制数(some support was added in 10g)。 数字以内部格式保存,除非您使用隐式或显式 TO_CHAR,否则由“客户”来显示它们(或任何想要的“美化”)。

    select to_number('1e-1') num, 
           to_char(to_number('1e-1'),'9.9EEEE') sci_num, 
           to_char(to_number('1e-1')) std_num 
    from dual;
    
                NUM SCI_NUM   ST
    --------------- --------- --
                .10   1.0E-01 .1
    

    【讨论】:

      猜你喜欢
      • 2021-04-19
      • 1970-01-01
      • 2016-11-15
      • 2021-05-14
      • 2018-01-12
      • 2020-07-26
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多