• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

show a minus sign as an output instead of the parentheses

Explorer ,
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

626

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jun 06, 2006 Jun 06, 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

Votes

Translate

Translate
LEGEND ,
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

Saving it where, and displaying it how?

Phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

<CFOUTPUT>
<CFIF foo LT 0>-</CFIF>#NumberFormat(Abs(foo), "999,999,999.99")#
</CFOUTPUT>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 06, 2006 Jun 06, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2006 Jun 07, 2006

Copy link to clipboard

Copied

LATEST
I missed the second part of the numberformat function which is minus sign before negative number. thank you SafarTech and others.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation