Page 1 of 1

Adding a thousand separator

Posted: Wed Apr 05, 2006 3:15 pm
by wjcampbe

How easy would it be to amend NorPrice to format the output with a thousands separator on currencies such as Japanese Yen?

Finance Director does not like the current display.


Posted: Wed Apr 05, 2006 4:14 pm
by norman
NorPrice displays the alternate currency in 2 ways. If the exchange rate is below a certain value (CUSTOMVAR:HIDEFRACTIONRATE) it uses nnnn.nn If the exchange rate is above it just displays the integer value.

Neither of these routines do any comma type formatting. It wouldn't be hard to add, however. All you'd need to do is alter 2 files

Cart and Checkout the Perl routine, lines the format strings within

$sFormattedPrice .= sprintf(" (%d $iso)", $nNorprice);


$sFormattedPrice .= sprintf(" (%1.2f $iso)", $nNorprice);

for the integer and decimal version.

For the Product page, norpricesupport.js JavaScript and the lines are

return prefix + ' (' + optplus + Math.round(altprice) + ' ' + isoname + ')' + suffix;


return prefix + ' (' + optplus + topounds(altprice) + ' ' + isoname + ')' + suffix;

where the Math.round(altprice) and topounds(altprice) would need some code added to fit in the commas.

This ... atting.htm page contains some routines for both Perl and JavaScript.

Posted: Wed Apr 05, 2006 4:59 pm
by wjcampbe
Excellent Norman,

Will let you know how I get on.


Posted: Thu Apr 06, 2006 2:00 am
by wjcampbe
I'm almost there.

I have working javascript when there is a fraction in the result, but not when the result is a whole number.

I have consistently working perl.

Want a copy back when I'm finished? :D


Posted: Thu Apr 06, 2006 2:15 am
by norman
Yes please.

I was going to look at adding this myself when I had some free time but anything that speeds that up will be useful.

Posted: Thu Apr 06, 2006 9:43 am
by wjcampbe
Have sent an email - perfect perl and partial javascript. Still working on it.


Posted: Thu Apr 06, 2006 2:12 pm
by norman
Just emailed you what's hopefully a solution.

Posted: Thu Apr 06, 2006 2:16 pm
by wjcampbe
I just came on to say my solution is now working 100% in everything except Opera 9.

OK in IE6, IE7, Firefox and Opera 8.5.

Will look at your solution, and see if it's the same change I made, then come back at you.

Posted: Thu Apr 06, 2006 3:26 pm
by wjcampbe
Nope - the javascript would not work. I will send you the one I have working.


Posted: Thu Apr 06, 2006 3:40 pm
by wjcampbe
Just got your patched javascript - it works - so much neater and more compact than what I had :oops: - guess I won't send you anything new after all.

Thanks loads, Norman.

Posted: Sun Apr 09, 2006 12:21 am
by norman
I can't take too much credit. I got most of it from the O'Reilly Perl Cookbook.