Extension talk:NumberFormat


Great extension!

Hello Patrick & Pavel,

I just wanted to say "Thanks a lot" for this great extension!

On my site I show prices with help of SMW. The problem was that prices like 27,10 € were shown as 27,1 € and not as 27,10 €. First I played around with {{padright:{{#ifeq:{{#len:foo}}|2|foo,|foo}}|5|0}} (which worked), but then I found your extension which is much more convenient.

Just a hint for German users: If you have a number like 27,1 and want to convert it to 27,10 use the following code:

{{#number_format:your_number|2|,|.|,}}

Thanks again! Stefahn (talk) 11:32, 20 May 2013 (UTC)

Thanks for the feedback! I am glad that this extension helps you :-) Pastakhov (talk) 16:37, 20 May 2013 (UTC)

Inlilne Queries

I love the idea of your extension. I am currently working on a pet project to build a complete, semantic CMDB so I need to be able to get rid of the comma in Office 2010 (just for example).

Do you know how I could use this function for inline quieries and the like? Most everything I'm doing is storing each piece of information and it's properties (software title, product key, vendor, version, etc) as one 'page' and calling queries throughout the rest of the site to aggregate all of that data together, using the semantic properties to pull exactly what we need every time.

Any help would be greatly appreciated! 205.209.247.222 04:43, 12 July 2013 (UTC)

Hi, I'm not quite sure what the problem is.
I use this extension to clean the user input: [[MyNumberProperty::{{#number_format:{{{Value|0}}}|_|.||,}}]]
And clear the result of the query:
{{#ask: ...
|?MyNumberProperty
| mainlabel=-
| format=array
| name=myArray
}}
{{#arrayprint:myArray |<br /> |@@@@|{{#number_format:{{#explode:@@@@|<PROP>|0}}|_|.||,}} }}
There may be bugs, so it is not a real-life example.
For simplicity, I use a template Num: {{#iferror: {{#if: {{{1|}}} | {{#number_format:{{{1|0}}}|_|.||,}} | 0 }} | 0 }}
Then, {{#arrayprint:myArray |<br /> |@@@@|{{Num|{{#explode:@@@@|<PROP>|0}}}} }} Pastakhov (talk) 05:55, 12 July 2013 (UTC)
The problem is quite obviously me.  :)
In all seriousness, I'm just getting my feet wet with MediaWiki. I tried out DokuWiki but it was so limited, so I'm coming into MediaWiki with bad forms already in my head, and I've only been at it a week or two. That's why I asked how one would accomplish it, not if it could.
And thank you for the awesome example. You have given me more fodder for learning in this one message than I have seen all week. I'm loving all that SMW will do, and I'm trying to learn it as fast as I can. But it seems like I'm coming in late in the game!
I'll try your example out tomorrow and see if I can figure out the syntax.
Thanks again! Cjg1979 (talk) 06:18, 12 July 2013 (UTC)

Negative numbers

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Hi, it seems that this extension doesn't work with negative numbers. Is that correct? I thought it would be a good alternative for formatnum, because formatnum gives errors with php 5 and this one doesn't. But I didn't think it would ignore negative numbers. Is this a bug? AdSvS (talk) 11:59, 16 June 2014 (UTC)

Hi! Yes, it is a bug. I'll fix it, thanks for report. Pastakhov (talk) 13:48, 16 June 2014 (UTC)
The bug has been fixed in version 0.8.0 Pastakhov (talk) 15:22, 16 June 2014 (UTC)
That's absolutely great. Thank you for your effort and work. This is much appreciated! [[kgh]] (talk) 15:35, 16 June 2014 (UTC)
Indeed it is! Thanks Pavel!
Sorry that my php-knowledge is non-existent... AdSvS (talk) 17:03, 16 June 2014 (UTC)
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Tagging version 0.8.1

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


@User:Pastakhov It will be nice if you could tag this commit with 0.8.1

Thanks and cheers [[kgh]] (talk) 15:01, 16 December 2015 (UTC)

Done Pastakhov (talk) 05:22, 18 December 2015 (UTC)
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

PHP Warning: number_format()

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Setup
  • MediaWiki 1.29.0-rc.1 (929f8dc) 01:59, 8 July 2017
  • PHP 5.6.30-0+deb8u1 (apache2handler)
  • MariaDB 10.0.31-MariaDB-1~jessie
  • NumberFormat 0.8.1 (e879011) 14:15, 15 August 2015
Issue

PHP Warning: number_format() expects parameter 2 to be long, string given in /../w/extensions/NumberFormat/NumberFormat.php on line 81

@Pastakhov: I cannot tell exactly if this started out after the upgrade to 1.29 or if this was already present before. I found this in the servers error log. [[kgh]] (talk) 08:19, 10 July 2017 (UTC)

Thanks for report, see https://gerrit.wikimedia.org/r/364167 Pastakhov (talk) 08:45, 10 July 2017 (UTC)
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Question about thousands separator

Our wiki needs to get for example 1234.50 from 1234.501 (IOW: no thousands separator and 2 decimal places) but the round function of PHP doesn't keep dangling zeros and therefore the same is true for the round available in #expr. Would we get the requested result by {{#number_format:1234.501|2|.|}}?

Maybe this question seem redundant, but the combination of empty thousands_sep and dangeling zeros is crucial for us and the French example combines a lot of features which (sort of) confuses me. Thanks for your help :)
--Uncopy (talk) 21:17, 26 October 2018 (UTC)

BTW: the example link is broken. Hopefully, the next will be somewhere on https://xen.wiki --Uncopy (talk) 21:37, 26 October 2018 (UTC)
Hi,
{{#number_format:1234.501|2|.|}}
returns 1234.50 Pastakhov (talk) 13:37, 27 October 2018 (UTC)

Fatal error: Cannot redeclare number_format_Setup()

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Reported with T219061. Probably an issue with PHP 7.2.x!? [[kgh]] (talk) 11:24, 23 March 2019 (UTC)

The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Is there a way to make this work on 1.32?

Or is there any alternative to format numbers? Thanks! <3 Extarys (talk) 21:27, 23 May 2019 (UTC)

What's wrong on 1.32? [[kgh]] (talk) 22:41, 23 May 2019 (UTC)
It complains there is no extension.json or something...
I'm sorry I should have been more precise. Extarys (talk) 00:57, 24 May 2019 (UTC)
This is expected. Did you follow the installation instructions? [[kgh]] (talk) 05:49, 24 May 2019 (UTC)
Oh Silly me, I was convinced that the old way of importing extensions was deprecated... Thanks, adding the require_once worked. Sorry and thanks for your time! Extarys (talk) 06:35, 24 May 2019 (UTC)

extension does not work

Unfortunately, this extension does not work.

{{#number_format:2.7182818284590452353602874713526624977572470936999595749669676|_}}

displays as

2.7182818284590450907955982984276488423347473144531250000000000

instead of

2.7182818284590452353602874713526624977572470936999595749669676

Nicole Sharp (talk) 20:09, 29 March 2021 (UTC)