Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep 2 decimal places in delphi?

Tags:

decimal

delphi

I have to selected some column data from a database table and make this data with two decimal places only. I see this

SQL.Strings = ('select' #9'my_index '#9'his_index,'...

What is that #9?
How can I deal with the data I selected to make it only keep two decimal places?
I am very new to Delphi.
Thanks!

like image 731
spspli Avatar asked Nov 27 '22 14:11

spspli


2 Answers

#9 is the character with code 9, TAB.

If you want to convert a floating point value to a string with 2 decimal places you use one of the formatting functions, e.g. Format():

var
  d: Double;
  s: string;
...
d := Sqrt(2.0);
s := Format('%.2f', [d]);
like image 112
David Heffernan Avatar answered Dec 11 '22 01:12

David Heffernan


function Round2(aValue:double):double;    
begin    
  Round2:=Round(aValue*100)/100;    
end;
like image 30
RTS Avatar answered Dec 11 '22 01:12

RTS