Folks,
As a Java Script Kiddy. I need some assistance from someone with Javascript in tiddlywiki skills.
I have a working filter operator called thousands. I am not sure where I obtained the JS code to do this but I added it to $:/core/modules/filters/math.js and it works well $__core_modules_filters_math.js.json (7.0 KB)
- eg
{{{ [[1000345.3]thousands[]] }}}
produces1,000,345.3
.
However I would like to turn this into a standalone filter operator module, rather than overwrite the core modual.
I placed the following in its own tiddler but it is not working. I believe it needs access to other functions found in $:/core/modules/filters/math.js
exports. Thousands = makeNumericBinaryOperator(
function(a) {
// Splitting the number into integer and fractional parts
var parts = a.toString().split(".");
// Formatting the integer part with commas
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
// Concatenating the integer and fractional parts back together
return parts. Join(".");
}
);
Further I am aware that other “languages” use the opposite to us in Australia, So wonder how to parameterise this or obtain these from localisation.
- eg
{{{ [[1000345.3]thousands[]] }}}
would produce1.000.345,3
.
Some assistance would be appreciated.