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
0 Sergey Alexandrovich Kryukov 6,745
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,599
4 Gihan Liyanage 2,650


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100