【问题标题】:How can I convert any numbers, for example 822042461 (string-type) to 822042461 (double-type)?如何转换任何数字,例如 822042461(字符串类型)到 822042461(双类型)?
【发布时间】:2021-04-14 21:12:42
【问题描述】:

如何在 C++ 中转换任何数字,例如 822042461(字符串类型)到 822042461(双精度类型)?非常感谢!

【问题讨论】:

  • 这可能取决于您使用的编程语言。
  • 好的,我添加了smth

标签: string visual-c++ type-conversion double c++17


【解决方案1】:

sscanf 可能有用:

/* sscanf example */
#include <stdio.h>

int main ()
{
  char sentence []="822042461";
  double i;

  sscanf (sentence,"%lf",&i);
  printf ("%lf\n",i);

  return 0;
}

$ gcc -o /tmp/test.exe  /tmp/test.cpp
$ /tmp/test.exe                      
822042461.000000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    • 2022-08-18
    • 2019-01-07
    相关资源
    最近更新 更多