使用setprecision()进行舍入值的问题; [英] Problem using to rounding value with setprecision();

查看:82
本文介绍了使用setprecision()进行舍入值的问题;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys!

我需要使用C ++ builder 6来计算我想要的小数位数。

我在google上看到,那就是我需要的setprecision(),但我不能在备忘录上显示它



但是,当我点击按钮时,显示它:3,73456001281738
我不明白..



Hello Guys!
I need to round numbers with how many decimals i want, using C++ builder 6.
I saw on google, that to do that i need the setprecision(), but i can''t show it
on a Memo!
But, when i click on button, shows it: 3,73456001281738
I don''t understand..

#include<iostream>
#include<sstream>
#include<iomanip>

void __fastcall TForm1::Button1Click(TObject *Sender)
{

        AnsiString strValue;

        setprecision(2);
        float value = 3.73456;
        strValue = FloatToStr(value);


   Memo1->Lines->Add(" " + strValue);
}



如果我错过了什么,请纠正我。我是新来的。

谢谢!!



PS *(对不起英语,我正在学习,所以。放轻松..)


If i miss something, correct me please. I''m new here.
Thanks!!

PS* (sorry for the english, i''m learning, so.. take it easy..)

推荐答案

使用 FloatToStrF [ ^ ]功能


你最好看看提升 [ ^ ]库。它有许多有用的数学函数。
You better take a look at boost[^] library. Its with lots of useful mathematical functions.


这篇关于使用setprecision()进行舍入值的问题;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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