Click here to Skip to main content
Sign Up to vote bad
good
See more: C++
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);
}
If i miss something, correct me please. I'm new here.
Thanks!!
 
PS* (sorry for the english, i'm learning, so.. take it easy..)
Posted 11 Dec '12 - 17:35


2 solutions

use FloatToStrF[^] function
  Permalink  
Comments
Thales Maggi - 13 Dec '12 - 12:25
Thaanks! It help me a lot! I'll make another ask, if you have time to answer again! hehe
You better take a look at boost[^] library. Its with lots of useful mathematical functions.
  Permalink  
Comments
Thales Maggi - 13 Dec '12 - 12:25
Thank you too!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 415
1 OriginalGriff 325
2 Arun Vasu 268
3 CPallini 213
4 Tadit Dash 203
0 Sergey Alexandrovich Kryukov 10,005
1 OriginalGriff 7,654
2 CPallini 4,171
3 Rohan Leuva 3,447
4 Maciej Los 2,974


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid