01499: Markup Expression number_format

Summary: Markup Expression number_format
Created: 2024-02-19 19:52
Status: Open
Category: Feature
From: simon
Priority: 4
Version: any
OS: any

Description: Please add access to https://www.php.net/manual/en/function.number-format.php as a MarkupExpressions in the core


{(nrfmt num dec=num decsep="str" thsep="str" )}

named parameters would be optional and override the locale defaults


Wouldn't it be better to use a locale instead? NumberFormatter can output numbers, currencies, and even spell out the numbers, in different languages. --Petko

Yes, probably, I wasn't aware of Locale

Use Case:
Some recipes expose variables that are numbers, e.g.

{(nrfmt {*$ThumbList_k} )}
would display "9,999" (depending on locale)

I have added a Thumblist question variable "?s" with the human-readable file size in binary units, so 9,999 kb would show "9.7M". There is a PmWiki core helper function FileSizeCompact($n, $precision=1) for this. --Petko

Awesome, thanks, could we please also have "?S" for metric SI units
Note that in the "?s" variable the Binary unit should strictly be "Mi".

Added "?S" for decimal units with PmWiki 2.3.21 and ThumbList 20240321. I don't want to add Ki-, Mi-, etc. for now, it only shows the the first letter, like 100k or 1.2M (not 100kB or 1.2 MB), and this would be used for example in Attachlist or Attachtable. I'd even remove "b" and only show the number when under 1k. BTW "?k" is also in binary. It may be better to use decimal in attachlist. People who strictly require the Ki- prefixes should either add them or have their own functions. --Petko