Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hot to format a number to force the "+" sign to show when > 0?

Status
Not open for further replies.

agc1976

Programmer
May 2, 2001
36
PR
Well, the subject speaks for itself. I want to format a field so that it shows the "+" sign when the number is positive and the "-" sign when the number is negative.

Is this possible without converting the number to a string?
 
You'll have to convert it to a string when it's greater than 0.

IIf([MyNumber]>0,"+"&[MyNumber],[MyNumber])

HTH Joe Miller
joe.miller@flotech.net
 
You can also use the format function. If you type in user-defined formats in the function you can have several "fields" in the format. The first one is for positive numbers, the second one (if specified) for negative and the third one (if specified) for zero values.

For example, you could have:

Code:
Format(MyNumber, "+#,##0;-#,##0;#,##0")

Alex Middleton
 
If the field type is set as Number in the table the negative numbers will be automatically have a minus (-) sign. Then is your form's module where this field gets calc'd, you can put an If statement to change the format for positives.

If MyNumber > 0
Then MyNumber.Format = "+0"
End if

Hope this helps.

B-) ljprodev@yahoo.com
ProDev
MS Access Applications
 
Thanks for your replies... I think I'm going with the following:
Format(MyNumber, "+#,##0;-#,##0;#,##0")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top