Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: StringGrid Display x Decimals


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Jan 29, 2016 1:53 PM Last Post By: Andrew McIsaac
Andrew McIsaac

Posts: 93
Registered: 3/12/13
StringGrid Display x Decimals  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 29, 2016 1:03 PM
Good Afternoon,

I'm sure this question is an easy one, but I am stuck nonetheless.
This case using C++ Ent XE3,

I have a StingGrid to Summarize different values from different SQL tables,
I am able to write to this, all is good, I am getting the data required.
Problem is the format - 126.00 displayed as 126, and 126.22 will be 126.22.
Is there an easy ( thinking on the OnDrawCell ) to set column ranges for decimal places ?

Thanks in Advance.
Andrew

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: StringGrid Display x Decimals  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 29, 2016 1:30 PM   in response to: Andrew McIsaac in response to: Andrew McIsaac
Andrew wrote:

I have a StingGrid to Summarize different values from different SQL
tables, I am able to write to this, all is good, I am getting the data
required. Problem is the format - 126.00 displayed as 126, and 126.22
will be 126.22. Is there an easy ( thinking on the OnDrawCell ) to set
column ranges for decimal places ?

TStringGrid only knows about strings, nothing else. You don't need to use
the OnDrawCell event, you can simply format your decimal strings the way
you want them to look before putting them in the TStringGrid to begin with.
Look at the SysUtils.FormatFloat() function, for instance. It lets you
specify the number of decimal places, even when the decimal value is 0.

--
Remy Lebeau (TeamB)
Andrew McIsaac

Posts: 93
Registered: 3/12/13
Re: StringGrid Display x Decimals  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 29, 2016 1:33 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
That was fast. :)

Will look into.

Thank you.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: StringGrid Display x Decimals  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 29, 2016 1:35 PM   in response to: Andrew McIsaac in response to: Andrew McIsaac
El 29/1/16 a las 22:03, Andrew McIsaac escribió:
Good Afternoon,

I'm sure this question is an easy one, but I am stuck nonetheless.
This case using C++ Ent XE3,

I have a StingGrid to Summarize different values from different SQL tables,
I am able to write to this, all is good, I am getting the data required.
Problem is the format - 126.00 displayed as 126, and 126.22 will be 126.22.
Is there an easy ( thinking on the OnDrawCell ) to set column ranges for decimal places ?

Thanks in Advance.
Andrew

Assign the cell value using the FloatToStrF function with the ffFixed format:

   int Row= ...;
   int Col= ...;
   double Value= ...;
 
    StringGrid1->Cells[Col][Row]= FloatToStrF(Value, ffFixed, 8, 2);


The last parameter is the number of decimals digits
Andrew McIsaac

Posts: 93
Registered: 3/12/13
Re: StringGrid Display x Decimals  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 29, 2016 1:53 PM   in response to: Antonio Estevez in response to: Antonio Estevez
Thank you both so much.

It will now look like I know what I'm doing :)

Thanks
Andrew
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02