简体   繁体   English

如何在C程序中将十进制数转换为64位浮点数?

[英]how to convert a decimal number into 64 bit floating point number in C program?

I am working on block compressed sparse row format of sparse matrix. 我正在研究稀疏矩阵的块压缩稀疏行格式。 I need to convert a nonzero element into 64 bit floating point. 我需要将一个非零元素转换为64位浮点数。 I need a syntax in c OR C++ for that? 我需要使用C或C ++的语法吗?

Do you have your number saved as a string? 您的号码是否另存为字符串? If yes do (this will work in both C and C++): 如果是的话(这将在C和C ++中都起作用):

const char *number = "11.111"; // This the variable holding your number
double num = atof(number); // This is your number saved as a double, that is usually 64 bit

If you have it saved as an int , double , float you can simply do: 如果将其另存为intdoublefloat ,则只需执行以下操作:

double num = other_variable;

Again, it will work in both C and C++. 同样,它将在C和C ++中都可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将十进制数转换为64位浮点双精度二进制数? - a decimal number into 64 bit floating point double precision binary? 如何将十进制数转换为64位二进制浮点数? - How to convert decimal number into 64 bit binary float number? 如何将 64 位浮点数添加到特定索引处的 unsigned char 数组(C++) - How can I add a 64 bit floating point number to an unsigned char array at specific indexes (C++) C ++将浮点数转换为字符串 - C++ convert floating point number to string 如何将浮点数转换为精确的字符串? Arduino C++ - How to convert a floating point number into a string with precision? Arduino C++ 如何在C ++中进行32位十进制浮点数乘法? - How to do 32 digit decimal floating point number multiplication in C++? 如何在两个浮点数之间找到最短的十进制数 - How to find shortest decimal number between two floating point numbers 在质数 C++ 程序中不断得到浮点异常 - Keep getting floating point exception in prime number c++ program 在 C++ 中将浮点数转换为本地化字符串 - Convert a floating point number to a localized string in C++ 如何在一定数量的小数位(没有舍入)后截断浮点数? - How to truncate a floating point number after a certain number of decimal places (no rounding)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM