C ++:什么是双转换为字符串的最佳方式? [英] C++: what is the optimal way to convert a double to a string?

查看:74
本文介绍了C ++:什么是双转换为字符串的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最优化的方式来达到同样的机会吗?

 无效美孚(双的floatValue,字符* stringResult)
{
    sprintf的(stringResult,%F的floatValue);
}


解决方案

我可能会与你在你的问题建议去什么,因为没有内置ftoa()函数和sprintf让您的格式控制。谷歌搜索ftoa汇编给出了一些可能有用的结果,但我不知道你想要去那么远。

What is the most optimal way to achieve the same as this?

void foo(double floatValue, char* stringResult)
{
    sprintf(stringResult, "%f", floatValue);
}

解决方案

I'd probably go with what you suggested in your question, since there's no built-in ftoa() function and sprintf gives you control over the format. A google search for "ftoa asm" yields some possibly useful results, but I'm not sure you want to go that far.

这篇关于C ++:什么是双转换为字符串的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆