# Coerce number into numberFormatted integer--How?

Sivakatirswami katir at hindu.org
Wed Jul 10 00:51:01 EDT 2002

```Well, developing CGI for the net on Mac OSX with Darwin on your own station
really "rocks" as the kids say...thank you Scott Raney!

I am in the middle of developing a mini ecommerce site for where people can
purchase a coloring book in quantity... It's soooo very simple with MC/Rev

Minor problem: shouldn't numberformat recognize and format a simple integer
returned by a function? If I set the numberFormat to "#.00" we get:

Subtotal 30.00
Shipping and handling: 8
Total 38.00

If I comment that out I will get
30
8
38

So, we can see it *is* working.. But how to coerce the simple integer that
is not a result of math into the dollar format... I *can* just "fake" a
calculation put (1*tShipping) into tShipping. And that works, but, hoping
not to have to be doing that in the long term, as one day someone else
looking at the code will be asking "What is That for?" I suppose if there is
no other option we will just explain that line with a comment... And end up
with two extra lines of workaround code.

Shouldn't numberFormat recognize a numeric value returned by a function as a
"calculation" of sorts?

Script snipped below.

#!mc
On startup
if \$REQUEST_METHOD is "POST" then
## put the form data into an array
put  urlDecode (it)  into tDataIn

split tDataIn by "&" and "="
if "buyer_location" is among the lines of keys(tDataIn) then
## this is the initial selection of product/location/quantity choices
## so we process the quantity to build the order form.
## one version for all foreign orders and one version for USA/Canada
set the numberformat to "#.00"
put (tDataIn[quantity]*3.75) into tSubTotal
put calculateShipping (tDataIn[quantity]) into tShipping
put tsubtotal+tshipping into tTotal
put url "file:/Users/katir/Sites/mystic_mouse/mouse_order_form.html" into
tOrderForm
replace "###Quantity###"  with tDataIn[quantity] in tOrderForm
replace "###Subtotal###"  with tSubtotal in tOrderForm
replace "###Shipping###"  with tShipping in tOrderForm
replace "###Total###"  with tTotal  in tOrderForm

put  tSubtotal & "<BR>" & tShipping into tResponse

put "Content-Type: text/html" & cr
put "Content-Length:" && the length of tResponse & cr & cr
put tResponse
end if
end startup

function calculateShipping x
switch
case (x>4 and x<11)
put 8 into tShipping
break
case (x>10 and x<16)
put 9 into tShipping
break
case (x>15 and x<21)
put 10 into tShipping
break
case (x>20 and x<26)
put 11 into tShipping
break
case (x>25 and x<31)
put 12 into tShipping
break
end switch
return tShipping

end calculateShipping
=========

Hinduism Today

Sivakatirswami
Editor's Assistant/Production Manager
katir at hindu.org