[ic] Distributor prices more then 2 decimals

Daniel Davenport ddavenport at newagedigital.com
Wed Jun 22 18:51:55 EDT 2005



>>> info at alengio.com 06/22/05 10:01 AM >>>
> Hello fellow IC users,
> 
> I am currently using IC for my web shop were I also sell B2B. I am using the
> dealer status which is made up of two price levels; Retail and Distributor.
> The distributor prices are calculated based on an X discount over the retail
> prices. However after this discount the prices are not a 2 decimal number
> any more. This causes a difference between the displayed and the correct
> price level for people with a distributor dealer status. 
> 
> The question:
> Is there are solution which allows me to change the distributor prices such
> that they only have 2 decimals (0,00 USD) 

I'd recommend the [currency] tag, which makes nembers look like money,
including adding or removing decimal places....but it also likes to add the money
symbol ('$' around here).  You might or might not want that.

The simplest way i know of....

[tmp the_price]3.14159[/tmp]
[calc] sprintf "%.2f", $Scratch->{the_price} [/calc]

For reference, it looks like it likes to round everything up to _and including_
.xx5 down toward 0.  Depending on where you learned math, you might need to
add a tiny fudge factor, say .0000001, in order to make it round 'correctly'.

If you already use a [calc] tag to figure the prices, or you already figure them
via perl, stick the sprintf there and save a step.


There's also this.... :)

CodeDef round Filter
CodeDef round Routine sub { sprintf "%.$_[2]f", (($_[0] || 0) + .000000001) }

Put that in a file in $IC_DIR/code/Filter, or just insert it into interchange.cfg.

Use it like 

[filter round.2]3.14159[/filter]
or
[filter op="round.2" interpolate="1"][scratch total][/filter]
or even
[data table=products field="price" key="3663a" filter="round.2"]

The .number is how many decimal places you want.

Enjoy :)
/




More information about the interchange-users mailing list