Calculating with Format Currency Comma?

# Thread: Calculating with Format Currency Comma?

1. Al (pogey) Gore Guest

## Calculating with Format Currency Comma?

I have an update query that calculates costs. If I use FormateCurrency on the page, then commas are placed in the numbers for 1,000. <BR><BR>But that causes an error when the calculate button is clicked and the "Page Cannot be Displayed."<BR><BR>IF I use CDbl on the update page, and nix the FormatCurrency on the form, then 3.50 is displayed as 3.5.<BR><BR>So how can I calculate with the FormatCurrency comma in there?<BR>OR how can I make CDbl always display two decimal places.<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
820

## RE: Calculating with Format Currency Comma?

Here&#039s what you want...<BR><BR>FormatNumber (Cdbl (YourNumber), 2)

3. Al (pogey) Gore Guest

## It didn't work

I used this, but it the page wouldn&#039t display<BR><BR>&#060;%=FormatNumber(CDbl(result("u nitprice"), 2))%&#062;

4. Senior Member
Join Date
Dec 1969
Posts
820

## Try this...

Replace(FormatNumber(Cdbl(1000.5), 2), ",", "") -&#062; 1000.50<BR><BR>Replace will also work with FormatCurrency but then you get \$1000.50

5. jd
Senior Member
Join Date
Dec 1969
Posts
850

## RE: Calculating with Format Currency Comma?

Your question does not make sense to me. It almost sounds like you are saying that you are trying to do math with variables that have been modified with formatcurrency, e.g.<BR><BR>total = formatcurrency(subtotal) * .075<BR><BR>This, of course, will not work. You should do your math FIRST, and then apply formatcurrency to the results, e.g.:<BR><BR> total = formatcurrency(subtotal * .075)<BR><BR>or<BR><BR> total = subtotal * .075<BR> response.write formatcurrency(total)<BR><BR>Does that make sense?<BR><BR>

6. Al (pogey) Gore Guest

## Is this Fuzzy Math? Almost works, but . . .

That works if a number is inserted as you have it, but if I insert rs("unitprice") it displays the page with a blank field for unitprice.<BR><BR>=Replace(FormatNumber(Cdbl(resul t("unitprice"), 2), ",", ""))<BR><BR>Can I insert rs("unitprice") in there?

7. Al (pogey) Gore Guest

## RE: Calculating with Format Currency Comma?

I have the recordset displayed on Calc.asp with FormatNumber applied, and when the button is clicked, it goes to update.asp and after the tables are updated, the user is directed back to Calc.asp, where formatting is applied.<BR><BR>It seems that even if I directed him to another page, I will have the comman problem, because what if he wants to calculate agian, and again . . . ?<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
820

## Anyone else want to take a shot at this??

Seems to me that it should work. Only thing I can think of is if you&#039re returning an empty recordset. What do you get if you do a response.write result("unitprice")?

9. amy
Senior Member
Join Date
Dec 1969
Posts
141

## RE: It didn't work

In your formula, the ",2" is in the wrong place. It belongs with the FormatNumber function, not the CDbl function. The formula should be:<BR><BR>&#060;%=FormatNumber(CDbl(result("unitp rice")), 2)%&#062;<BR><BR>Does that help?<BR>

10. jd
Senior Member
Join Date
Dec 1969
Posts
850

## RE: Calculating with Format Currency Comma?

I can&#039t help any more on this one unless you show us the code. I have a feeling there&#039s a basic misconception here.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•