Thousand separators with commas

General questions relating to Joomla! 3.x. Please consider the availability of third-party templates and extensions when deciding which Joomla version to use.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
goble
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Sat Jan 09, 2010 11:23 am

Thousand separators with commas

Postby goble » Wed Sep 13, 2017 1:32 pm

Hello,

am using k2 custom fields to display a qty i.e 1,500,000 for a k2 item. When I insert the data with the comas, it is displayed with the comas correctly. However another module that is used to filter this field won't work, The later will only work when I don't use comas i.e 1500000 but I don't want the qty to be displayed this way in frontend.

Is there a way to tell Joomla to display the data using commas when my data does not include comas ? So that my data can be filtered correctly.

itoctopus
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3913
Joined: Mon Nov 25, 2013 4:35 pm
Location: Montreal, Canada
Contact:

Re: Thousand separators with commas

Postby itoctopus » Wed Sep 13, 2017 4:59 pm

You can do this in the layout of the item/module by using the PHP function "number_format()".
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter

goble
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Sat Jan 09, 2010 11:23 am

Re: Thousand separators with commas

Postby goble » Thu Sep 14, 2017 6:58 am

Many thanks, made a override like this:


Code: Select all

<?php echo $extraField->value; ?>
to:

Code: Select all

<?php echo number_format($extraField->value); ?>

goble
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Sat Jan 09, 2010 11:23 am

Re: Thousand separators with commas

Postby goble » Thu Sep 14, 2017 7:56 am

Hello,

my fields are dynamic i.e. the values are generated by "$extraField->value"
and some are text values which disappear when using the "number_format". Any ignore parameter (in "number_format") to prevent the text values from disappearing ?

goble
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Sat Jan 09, 2010 11:23 am

Re: Thousand separators with commas

Postby goble » Sat Sep 16, 2017 8:34 am

Hello,

just to sum up,

When value = 1234,

Code: Select all

<?php echo number_format($extraField->value); ?>
= 1,234 (perfect)
When value = abcd,

Code: Select all

<?php echo number_format($extraField->value); ?>
= "no data"

Just need to get a work around, so that my text values are not affected.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 23455
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: Thousand separators with commas

Postby Per Yngve Berg » Sat Sep 16, 2017 8:48 am

Use the function "is_numeric" first

http://php.net/manual/en/function.is-numeric.php

Do 1.500.000 work? What language is used on the site?

goble
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Sat Jan 09, 2010 11:23 am

Re: Thousand separators with commas

Postby goble » Sat Sep 16, 2017 12:50 pm

Hello, thanks for your help.

Language set to fr_FR, anyway I have tested the code below (no knowledge in PHP), but I guess there are syntax errors ;-) :

Code: Select all

<?php if (is_numeric($extraField->value)) {echo number_format($extraField->value)}
else
{echo ($extraField->value)}
?>

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 23455
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: Thousand separators with commas

Postby Per Yngve Berg » Sat Sep 16, 2017 1:06 pm

For fr_FR the format will be 1.500.000,00

The ";" to end the statements is missing.

Code: Select all

<?php if (is_numeric($extraField->value)) {echo number_format($extraField->value);}
else
{echo $extraField->value;}
?>

goble
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 150
Joined: Sat Jan 09, 2010 11:23 am

Re: Thousand separators with commas

Postby goble » Sat Sep 16, 2017 3:51 pm

Just perfect !!! 8)


Return to “General Questions/New to Joomla! 3.x”

Who is online

Users browsing this forum: archieb, Mr. Wimpy and 28 guests