Page 1 of 1

FMT function

Posted: Wed Jul 28, 2004 2:09 am
by fridge
I simply want to pad a field with a number of leading zeros but the specific number is the value of an argument passed to the code.

I have tried
PadUnSigArg1 = FMT(UnSigArg1, "Arg1'0'R")
which does not work

and
PadUnSigArg1 = 0(Arg1 - Len(UnSigArg1)):UnSigArg1
which almost works
0.0000000123456

I realise I can manipulate the second result to get what I want but can I do it cleaner?

Any solution would be greatly appreciated.

Posted: Wed Jul 28, 2004 3:04 am
by WoMaWil
If you want to write a routine with a total of 7 letters or digits and if your number is less then 7 and you want the rest to be filled with Zero you write the following code into your Routine:

Ans=FMT(Arg1,"7'0'R")

and if you want to have it flexible use a second Argument Arg2

pFormat=Arg2:"'0'R"
Ans=FMT(Arg1,pFormat)

That's it.

Wolfgang

Posted: Wed Jul 28, 2004 5:45 am
by ray.wurlod
Can you please delete this post from Editor's Corner?
It's not necessary to post on every Forum.

Wolfgang's answer is 100% correct. However there is an alternative syntax that some people prefer.

Code: Select all

Fmt(TheString, "R%":Arg1)
The "%" character has the special meaning of "use zero as a background character" in the formatted result.

Posted: Wed Jul 28, 2004 1:42 pm
by fridge
Thanks for the help guys!