Formatting negative dollar amounts in ColdFusion

Have you ever tried to format a number into a negative dollar amount with cents like -$1,000.00?

If you have, I’m pretty sure you experienced some weird things with ColdFusion that you thought “should” work.

First off, let’s take a look at dollarFormat():

value = dollarFormat(-1000);

This will give the following:  ($1,000.00)

Close, but instead of a minus sign before the $ sign, the whole amount is between parenthesis (mainly used to signify a negative amount in accounting).

Since dollarFormat() only takes 1 argument, that’s about all we can do with that.

Let’s try numberFormat():

value = numberFormat(-1000, ‘$_,___.__’);

This gives the following: $-1,000.00

Close, except for some reason the minus sign is after the $ sign instead of before it. I tried different variations passing in different format masks to numberFormat() but couldn’t make it format the way I want -$1,000.00

Adam Cameron has a solution:

value = createObject(“java”, “java.text.DecimalFormat”).init(“$##,####0.00;-$##,####0.00”).format(javacast(“double”,-1000));

He suggests to “use Java’s DecimalFormat which allows one to provide a formatting mask for both positive and negative numbers.”

The result is: -$1,000.00 which is exactly what I wanted! YAY!

Twitter Bootstrap

Remove Link Text in Bootstrap Print View

Twitter Bootstrap

Whenever you try printing a page that has a Twitter Bootstrap theme and there is an anchor tag linking somewhere, the link is converted into text and displayed when printed. This can be annoying if you don’t want to print the links.
Here’s how you remove this:

In bootsrap.css there’s a line:

@mediaprint{
...
  a[href]:after {
    content:" (" attr(href)")";
  }
...
}

This is what’s displaying the text after each link. Simply change the content to “none” and that should do it like so

@mediaprint{
...
  a[href]:after {
    content:none;
  }
...
}

Now you don’t have annoying links displayed in your printouts!