How can i turn of decimal figures ?? 100.00 BF to 100 BF

greenspun.com : LUSENET : S-Mart Shopping Cart : One Thread

How can i have the price of the products show as 100 BF instead of 100.00 BF ?? I need to disable the 2 decimals behind the price...

Thanks, Gerry

-- Gerry (gerryu@hotmail.com), April 06, 2000

Answers

In the new scripts, most of the formatting is done with the SPRINTF function. A typical use is:

$tmpprice = sprintf ('%.2f',$tmpprice); which takes $tmpprice and converts it to a floating decimal with two places to the right of the decimal place.

Search for 'sprintf' and remove the instance you wish to change. Don't reformat unless you want to involk the incidental sprintf behavior of rounding.

Here is Selena Sol on sprintf "The Perl printf is much like the printf function in C and awk in that it takes a string to be formatted and a list of format arguments, applies the formatting to the string, and then typically prints the formatted string to standard output, which in our case, is the Web browser.

The printf syntax uses a double quoted string which includes special format markers followed by a comma- delimited list of arguments to be applied to those markers. The format markers are typically in the form of a percent sign followed by a control character.

For example, the generic format of printf might look like the following code:

printf ("[some text] %[format] [other text]", [argument to be formatted]); "

Greg Swofford

-- Gregory Swofford (computer@web-store.net), April 06, 2000.


Moderation questions? read the FAQ