hi, I wanna to calculate the total in currency format $00.00. But the coding doesnt seems to work . Can u help me ?

total = Cstr(total) + Request.Cookies("jumlah")

Dani AI

Generated

The problem is that the value from Request.Cookies is a string (and may include a dollar sign or commas), so converting the running total to a string before adding (as in the original post) will either force concatenation or trigger a type error. Several replies correctly point to using a formatting function for display (, , , ), but none shows a safe, server-side workflow that:

  • validates and cleans the cookie text,
  • converts it to a numeric type for arithmetic, and
  • formats the final sum for display.

A safe pattern in classic ASP (VBScript) is: read the cookie, strip non-numeric characters that interfere with conversion (dollar sign, thousands separators), check IsNumeric, convert with CDbl (or another numeric cast), add to the numeric total, then format the result for output. Also handle a missing cookie and the possibility of multi-valued cookies.

Example (server-side VBScript):

Dim total, raw, clean
total = 0
raw = Request.Cookies("jumlah")
If raw <> "" Then
clean = Replace(raw, "$", "")
clean = Replace(clean, ",", "")
If IsNumeric(clean) Then
total = total + CDbl(clean)
End If
End If
Response.Write FormatCurrency(total, 2)

Notes and cautions:

  • Use Replace to remove currency symbols and grouping separators before conversion. CDbl will fail on "$1,234.56" unless cleaned.
  • Check IsNumeric to avoid runtime errors when the cookie is empty or malformed.
  • FormatCurrency uses server locale for symbol/decimal separators; use explicit formatting if a fixed dollar sign and dot-decimal are required.
  • If the cookie is multi-valued, read the specific subkey (Request.Cookies("jumlah")("subkey")) rather than the whole cookie.
    This approach keeps numeric operations numeric and confines formatting to the presentation step.

Recommended Answers

All 5 Replies

hi,

CStr is used to Convert from other format to String Format then how can u add the values of the two variables. K. Anyway U can use Format function like below

MsgBox Format("32234324", "$00,00").
Try it


Shailaja:)

use format(MoneyValue,"currency")

'where 10000000.99 is the Amount
MsgBox Format("10000000.99", "#,###.00")

Text1.Text = Format$(CDbl(Format$(Text1.Text, "#,###,##0.00")) + CDbl(Format$(Text2.Text, "#,###,##0.00")), "$###,##0.00")

your comments such a weak./.

all of you is such a weak programmer..

mga bobo!~!!!

Is it so? then give the comment/solution for the thread instead of these type of comments. These comments doesn't make you are a good programmer or wht you expect. k.

Have a great day,
Shailaja :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.