Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - how do you format a real number with leading zeros?

I need to format a real number with leading zeros in the whole number part prior to the decimal point. I know how to achieve this with integers, but the syntax for reals escapes me.

Number  := 1.234 ;
SNumber := Format ('%2.3f', [Number]) ;

This gives SNumber = ' 1.234' but I want '01.234'. Number is always 0..99.999

like image 736
rossmcm Avatar asked Oct 25 '16 21:10

rossmcm


1 Answers

Using SysUtils.FormatFloat:

SNumber := FormatFloat('0#.###',Number); 

will get 01.234

Six placeholders and a leading zero means to add leading zeros.

like image 123
LU RD Avatar answered Sep 26 '22 14:09

LU RD