Currencies and comma's

Fonk

No avatar

2006-01-08 20:45

Hello,

I am trying to create a japanese version of the quick.cart. While doing this, I found that the amounts in japan should not have a .00 at the end. Does anybody know how to display amounts without .00. Example: Y10000 instead of Y10000.00.

Thanks,
Fonk

roland

No avatar

2006-01-09 11:28

I have written a small and not so beauty, but working script for a problem something like that. You need to modify it, and will work. This script is something like number_format() in PHP.


<script language="JavaScript">

 function 
reverse_string(string_in)
 {
  var 
reversed '';
  for (var 
string_in.length>= 0x--) reversed += string_in.charAt(x);
  return 
reversed;
 }
 
 function 
insert_separator(string_inseparator)
 {
  var 
tmp '';
  for (var 
0<= string_in.lengthx++)
   if ((
== 0) && (!= 0) && (!= string_in.length))
    
tmp += string_in.charAt(x-1) + separator;
   else
    
tmp += string_in.charAt(x-1);

  return 
tmp;
 }

 function 
number_format(numberthousand_sepdecimal_sep)
 {
  var 
tmp number;
  var 
tmp2 ''tmp3 '';
  var 
int_part ''dec_part '';

  if (
tmp.indexOf('.') != -1)
  {
   
int_part tmp.substr(0tmp.indexOf('.'));
   
dec_part tmp.substr(tmp.indexOf('.')+1);
  }
  else
  {
   
int_part tmp;
   
dec_part '';
  }

  
int_part reverse_string(int_part);
  
int_part insert_separator(int_partthousand_sep);
  
int_part reverse_string(int_part);

  
dec_part reverse_string(dec_part);
  
dec_part insert_separator(dec_part'');
  
dec_part reverse_string(dec_part);

  
document.write(int_part decimal_sep dec_part);
 }

</script>

// and then apply some changes in the template where you need it

<a title="$lang[Add_to_basket]"><script>number_format('$ aList[fPrice]', ' ', ',');</script>&nbsp;$config[currency_symbol]</a>

Roland

roland

No avatar

2006-01-09 11:29

If somebody can do this with RegExp... please...

Roland

roland

No avatar

2006-01-09 11:38

I forget: You may need to include this script into the js/standard.js file. I hope it helps.

Roland

Fonk

No avatar

2006-01-10 00:28

Hi Roland,

Thanks for the quick response.
I am trying to get it to work. Unfortunately I don't know much about PHP yet. What I did sofar is to put the code in a standard.js file, I included the standard.js in head.tpl and tried to call number_format from products_list.tpl. Something like <script>number_format('1000',' ',',')</script>

The script doesn't return anything. Probably something stupid I am doing.

Tomorrow another day :)
Fonk

Roland

No avatar

2006-01-10 08:37

The standard.js file isn't automatically included in page.tpl? Anyway.

This script doesn't return anything, but writes it to the page. I have modified the code for your needs.


<script language="JavaScript">

 function 
reverse_string(string_in)
 {
  var 
reversed '';
  for (var 
string_in.length>= 0x--) reversed += string_in.charAt(x);
  return 
reversed;
 }
 
 function 
insert_separator(string_inseparator)
 {
  var 
tmp '';
  for (var 
0<= string_in.lengthx++)
   if ((
== 0) && (!= 0) && (!= string_in.length))
    
tmp += string_in.charAt(x-1) + separator;
   else
    
tmp += string_in.charAt(x-1);

  return 
tmp;
 }

 function 
number_format(numberthousand_sep)
 {
  var 
int_part number.toString();

  if (
int_part.indexOf('.') != -1int_part tmp.substr(0int_part.indexOf('.'));
  
int_part reverse_string(int_part);
  
int_part insert_separator(int_partthousand_sep);
  
int_part reverse_string(int_part);

  
document.write(int_part);
 }

</script>

<script>number_format('10001', ' ');</script>



The last line is just an example, don't copy into the standard.js or it will do an extra and useless output to the screen:-). (Now, if you copy the whole code into an .htm or .html file and run it by a web browser, you will see the result, what is 10 001, without any decimals or so.)

Now, as the standard.js contains the functions needed, you have to modify the temlates everywhere you need, like this:

original:


      
<td>
        
$aList[fSummary]
      </
td>



new:


      
<td>
        <
script>number_format('$aList[fSummary]'' ');</script>
      </td>



It may be "number_format($aList[fSummary], ' ')", because the script converts the number into string automatically. You will have to modify the .tpl files everywhere you need to format the numbers.

Roland

Roland

No avatar

2006-01-10 08:40

Change the "&lt;"-s to the "less than" character. It's a bug in the forum engine, it automatically replaces it.

Roland

Roland

No avatar

2006-01-10 08:48

And take care. In the orders_delivery.tpl let the last 2 numbers unchanged, or it will display the "total cost" 0 when you choose a courier. It is because it uses a JavaScript code to do the calculation, and it will se a string (formatted number with spaces or commas) where he needs a pure number with or without a decimal point, so it will return 0.0. That's the limitation of this solution. With further JS and PHP coding (inside the Quick.Cart) it can be fixed, but I don't want to do that.

Roland

neofrix

No avatar

2006-01-13 21:45

Roland,

I am green to java and php, still tried your script:

- script copied in standard.js
- line changed in products_list.tpl

before:

<a href="?p=ordersBasket&amp;sOption=add&amp;iProduct=$aList[iProd uct]&amp;iQuantity=1" class="cart" title="$lang[Add_to_basket]">$aList[fPrice]&nbsp;$c onfig[currency_symbol]</a>


after:

<a href="?p=ordersBasket&amp;sOption=add&amp;iProduct=$aList[iProd uct]&amp;iQuantity=1" class="cart" title="$lang[Add_to_basket]"><script><script>number _format('$aList[fPrice]', ' ');</script> &nbsp;$config[currency_symbol]</a>
<div class="clear"></div>


In the browser the figures dissapeare, and the JavaScript Console says:

Error: unexpected end of XML source
Source File: http://www.szarvasgomba.hu/bolt/index.php?p=productsList&iCategory=6
Line: 151, Column: 37
Source Code:
<script>number_format('1700.00', ' ');


Please tell me if you have any idea, what did I do wrong.

The zeros make nervous the buyers, so it would be great to cut down a bit.

Thanks

neofrix

neofrix

No avatar

2006-01-14 11:55

By the way, the number format of my wildest dreams is:

1.000,-

(This is for one thousand.)

neofrix

neofrix

No avatar

2006-01-16 08:11

The <script><script> error was fixed, but it did not change a thing.

neofrix

Roland

No avatar

2006-01-16 13:21

Hmm. Interesting. It works fine on www.jokergsm.hu/ebolt/

There is a "<script><script>" in your modified line. Use only one. Maybe it is the problem.

You can use it as "1.000,- Ft" if you modify the templates whenever you want to see this format. Just as you did it with the <script>...

Roland

Roland

No avatar

2006-01-16 13:24

Oh, I see now you have fixed the <script><script> problem, I forget it.
Well. I don't have any idea now.

Roland

Roland

No avatar

2006-01-16 13:27

There is a much better solution. I will use it too.

http://opensolution.org/forum/index.php?p=readTopic&nr=1525&page=999

Roland

neofrix

No avatar

2006-01-16 15:03

Thank you Roland, it's a promising solution. I will try it as soon as I can.

neofrix

Fonk

No avatar

2006-01-18 22:46

Thanks Roland,

It is working and in the other thread Nick is mentioning some other way which I will try as well.

Thanks again

Back to top
about us | contact