Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Format mask for numbers
Message
 
To
02/12/2008 20:16:21
Yh Yau
Ingenuity Microsystems Sdn Bhd
Kuala Lumpur, Malaysia
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01365281
Message ID:
01365302
Views:
14
>I have a need to display a numeric field on the report with options to have no decimals, 2 decimals, 3 decimals or more.
>Currently I'm using the format mask in the field expression to do this but unable to put a iif() condition on the format mask to dynamically change the format mask based on a public variable to decide on how many decimal points the format mask should have.
>
>Is there a way to do this?
>
>Thanks in advance.
>Yau

This works for us. Put it in a calling prg or in a procedure file.
*
* -------------------------------------------------------------------------
*
PROCEDURE lNumFormat
*
lParameters mNum
*
* Format the number so that only what is needed shows.
* if it is zero then a blank is returned.
* If a number is 4.00 then it is formatted to 4
* If a number is 4.50 then it is formatted to 4.5
*
if mNum = 0
  RETURN ''
endif
if int(mNum) = mNum
  RETURN transform(mNum,'999999')
endif
if int(mNum*10) = mNum*10
  RETURN transform(mNum,'9999.9')
endif
RETURN transform(mNum,'999.99')
Beer is proof that God loves man, and wants him to be happy. - Benjamin Franklin
John J. Henn
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform