Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:35pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

use FloatToStrF[^] function
  Permalink  
Comments
Thales Maggi at 13-Dec-12 12:25pm
   
Thaanks! It help me a lot! I'll make another ask, if you have time to answer again! hehe
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You better take a look at boost[^] library. Its with lots of useful mathematical functions.
  Permalink  
Comments
Thales Maggi at 13-Dec-12 12:25pm
   
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 910
1 OriginalGriff 523
2 Abhinav S 253
3 thatraja 245
4 Emre Ataseven 210
0 Sergey Alexandrovich Kryukov 8,282
1 OriginalGriff 4,750
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


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