Pages:

How do display prices without decimal point: 100.00 -> 100

Patrick

No avatar

2006-01-12 21:10

I searched almost every template file, but I was unable to figure it out. Is there any help? I need it in product listings and in product details, everywhere else it doesnt matters.

example 100.00 USD, and I nedd to show only this: 100 USD

I will be thankfull if anybody could help. Thanks!!!!
QuickCart is great :)

Patrick

Patrick

Roland

No avatar

2006-01-13 08:59

Here it is: http://opensolution.org/forum/index.php?p=readTopic&nr=1509

Roland

Roland

No avatar

2006-01-13 09:01

Don't forget to read the whole topic before doing anything!! :-)

Roland

Patrick

No avatar

2006-01-13 19:16

Sorry for bothering but i doesnt work for me.

First I inserted this code into standard.js

function reverse_string(string_in)
{
var reversed = '';
for (var x = string_in.length; x >= 0; x--) reversed += string_in.charAt(x);
return reversed;
}

function insert_separator(string_in, separator)
{
var tmp = '';
for (var x = 0; x <= string_in.length; x++)
if ((x % 3 == 0) && (x != 0) && (x != string_in.length))
tmp += string_in.charAt(x-1) + separator;
else
tmp += string_in.charAt(x-1);

return tmp;
}

function number_format(number, thousand_sep)
{
var int_part = number.toString();

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

document.write(int_part);
}

Second a tried to aplicate it in products_list.tpl like this:

<script>number_format('$aList[fPrice]', ' ', ' ');</script>

And it didn't do anything? Any suggestions?
Thanks for your time

Patrick

Patrick

No avatar

2006-01-13 19:21

And I have also tried this:

<script>number_format('$aList[fPrice]', ' ');</script>

Patrick

Patrick

No avatar

2006-01-13 23:36

I also tried your original script in separate .html file, it also dont work:

<script language="JavaScript">

function reverse_string(string_in)
{
var reversed = '';
for (var x = string_in.length; x >= 0; x--) reversed += string_in.charAt(x);
return reversed;
}

function insert_separator(string_in, separator)
{
var tmp = '';
for (var x = 0; x &lt;= string_in.length; x++)
if ((x % 3 == 0) && (x != 0) && (x != string_in.length))
tmp += string_in.charAt(x-1) + separator;
else
tmp += string_in.charAt(x-1);

return tmp;
}

function number_format(number, thousand_sep)
{
var int_part = number.toString();

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

document.write(int_part);
}

</script>

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

Patrick

Patrick

No avatar

2006-01-15 02:55

I finally have a dirty hack for this:

1) in tempates/products_list.tpl
(or in every other page where you want this effect)

2) plase this piece of code:

<script language="JavaScript">
window.onload = function() {

document.body.innerHTML = document.body.innerHTML.replace(/\d+\.\d{2}/g, function (matched) {

return Math.round(matched);

})

}
</script>


what it does?

i strips every .00 from every number, if you have 100.00 you get 100

Patrick

Roland

No avatar

2006-01-16 13:26

Nice solution, I was seeking something like that.

Roland

Patrick

No avatar

2006-01-16 13:31

Here follows the modified version that strip ".00 " in words point, two zeros and space, co you can add currency like this ",- Kc" so there is no space between price and currency.

Instructions same as above:
<script language="JavaScript">
window.onload = function() {

document.body.innerHTML = document.body.innerHTML.replace(/(\d+\.\d{2})\s*/g, function (matched, price) {

return Math.round(price);

})

}
</script>

Patrick

neofrix

No avatar

2006-01-17 09:44

Great idea.

Is there a solution to make the calculation first then to display the page? Because now the price appears first like this: 1000.00 then it changes to 1000.

neofrix

Roland

No avatar

2006-01-17 11:29

I am wondering why don't my script working? It works fine on www.jokergsm.hu/ebolt/ ... ????

Roland

Roland

No avatar

2006-01-18 09:22

>> Is there a solution to make the calculation first then to display the page?
>> Because now the price appears first like this: 1000.00 then it changes to 1000.

I think no. The script cannot change prizes that are not present on the page. It has to be called after the whole page had been generated.

Roland

Nick

No avatar

2006-01-18 12:19

I think it is easier to just change the price format string for sprintf from '%01.2f' to '%01.0f'.

Do this in:
\actions_admin\orders.php
\actions_client\orders.php
\core\other.php

Example:

  
/**
  * Return price format
  * @return float
  * @param float  $fPrice
  */
  
function tPrice$fPrice ){
    return 
sprintf'%01.0f'$fPrice );
  } 
// end function tPrice


Roland

No avatar

2006-01-18 15:57

Yupiiiii! That's the all best! I was searching something for that, but to find it, that's not so easy. Thanx a lot, man!

Roland

neofrix

No avatar

2006-01-24 13:46


This does not seem to work for me. Would somebody help?

Shoulr I simply copy this

function tPrice( $fPrice ){
return sprintf( '%01.0f', $fPrice );
} // end function tPrice


in the three files, or I have to change manually '%01.2f' to '%01.0f'?


neofrix

Nick

No avatar

2006-01-24 22:55

Yepp,change the '%01.2f' to '%01.0f'. The number after the dot tells how many digits the decimal should have.

Brady

No avatar

2006-01-25 18:45

it working for me but only for the orders page. on the product list page they still show .00

someone pls help...

Brady

No avatar

2006-01-25 18:46

btw i forgot, i'm using v1.1

Nick

No avatar

2006-01-26 09:58

If the products has been entered before you made the code changes to the decimals they have been stored in the database with decimals.

Check if it has been stored in the database as .00. Look in the file /db/products.php

If it has either edit the file /db/products.php or reeneter the products from the admin page.

shannon

No avatar

2006-02-13 23:36

yo!

shannon

Pages:
Back to top
about us | contact