Skip to main content
Inspiring
June 6, 2006
Answered

show a minus sign as an output instead of the parentheses

When I save a minus value, the output comes as (500.00). I think the parentheses are default for the minus value in cf. How can I display –500.00 instead of (500.00)? I looked at the numberformat function, but could not find the mask for it.
This topic is closed to new replies. Start a new post to keep the conversation going.
SafariTECHCorrect answer
Inspiring
June 7, 2006
according to MX7 help docs, if you use

NumberFormat(number,"-999,999")

it should place a minus sign at the beginning if negative and a blank space if it is positive.

this example is formatting for 6 digits with a thousands separator, but you could use any formatting mask

6 replies

Inspiring
June 7, 2006
I missed the second part of the numberformat function which is minus sign before negative number. thank you SafarTech and others.
Translate
SafariTECHCorrect answer
Inspiring
June 7, 2006
according to MX7 help docs, if you use

NumberFormat(number,"-999,999")

it should place a minus sign at the beginning if negative and a blank space if it is positive.

this example is formatting for 6 digits with a thousands separator, but you could use any formatting mask
Translate
Inspiring
June 6, 2006
I think that can be one of the solutions.
However,
the first time when I insert a minus value, it goes through w/o any problems, but when I update the minus value, i got an error message. so before I use ur select stmt, I need to have a conditional stmt to find a parenthesis to check if the value that I pass to the database is negative or positive. It would be nice if i can find any cf function to display a minus sign instead of a parentheses, "( )" for any minus values.

what i did on this issue before saving into database,
<cfif find("(", form.myprice)>
<cfset form.myprice = ReReplace(form.myprice, ",|\$|\(|\)", "", "ALL")>
<cfset form.myprice = "-" & form.myprice>
<cfelse>
<cfset form.myprice = ReReplace(form.myprice, ",|\$", "", "ALL")>
</cfif>

but I wonder if there are other solutions. thanks again.
Translate
June 6, 2006
<CFOUTPUT>
<CFIF foo LT 0>-</CFIF>#NumberFormat(Abs(foo), "999,999,999.99")#
</CFOUTPUT>
Translate
Participating Frequently
June 6, 2006
Saving it where, and displaying it how?

Phil
Translate
Inspiring
June 6, 2006
quote:

Originally posted by: HandersonVA
When I save a minus value, the output comes as (500.00). I think the parentheses are default for the minus value in cf. How can I display –500.00 instead of (500.00)? I looked at the numberformat function, but could not find the mask for it.

Here is how you would do it in oracle. Once you have the gist of it you can see if your own db supports it. by the way, || is oracle's concatonation operator.

select case
when numfield >= 0 then to_char(numfield)
else '-' || to_char(numfield * -1) end displaynumfield
etc
Translate