Format decimal text with leading zero's

fredp1fredp1 Member Posts: 86
Hi,

I've had a previous thread http://www.mibuso.com/forum/viewtopic.php?f=23&t=36144with great respsonses to the question.
I wanted to display leading zero's in a report for a 3 digit integer, e.g. text =5 display 005, text = 56 display 056, text =145 display 145.
Basically the solution was text := PADSTR('',3 - strlen(Text),'0') + Text;

Now I need to be able do the same thing with a decimal number. i.e. the integer portion is always 3 digits with zero padding any leading digits
e.g. text = 1.46, display 001.45
text =67.123 display 067.123
text = 145.7 display 145.7

I was thinking about the format command or do I need to pull apart the string to separate the integer/decimal.

Can anyone help?

Thanks

Answers

  • reijermolenaarreijermolenaar Member Posts: 256
    A variant on your previous solution would be:
    Text := PADSTR('', 3 - STRLEN(FORMAT(ROUND(DecimalVar, 1, '<'))), '0') + FORMAT(DecimalVar);
    
    Reijer Molenaar
    Object Manager
  • fredp1fredp1 Member Posts: 86
    Hi,

    Thanks for the reply, but the decimal variable is a text data type.

    The suggestion doesn't work on text fields.

    Can it be done?

    Thanjs
  • helmhelm Member Posts: 46
    Temporarily removing the decimals should work. Something like this.

    decText := COPYSTR(text,STRPOS(text,decimalSign),STRLEN(text));
    text := DELSTR(text,STRPOS(text,decimalSign),STRLEN(text));
    text := PADSTR('',3 - strlen(Text),'0') + Text + decText;
  • fredp1fredp1 Member Posts: 86
    Hi,

    Thanks for the response... I wan't sure if the Format command could be used or if I had to pull apart the string.

    Kind regards
    Fred
Sign In or Register to comment.