Click here to Skip to main content
12,250,546 members (47,370 online)
Rate this:
 
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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2016
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