Do you have some feature in mind that you'd love to see in Couch? Let us know.
5 posts Page 1 of 1
Good Evening!

As a matter of fact there are many Place Value Systems in place. CouchCMS happens to implement the International Place Value System by default.

Now as a use case, I need to display an amount. For ex:
Amount = 123456789.00
In International Place Value System it would be: 123,456,789.00
In Indian Place Value System it would be: 12,34,56,789.00


Up until PHP 7.3,x there exists a function money_format. But from > PHP 7.4.0 the function got deprecated and in PHP 8, it was totally removed.

So since PHP 7.4.0 and after, NumberFormatter Class is suggested to be used. An example of implementation can be found here.

My request would be, can there be a native implementation in CouchCMS as there is for time-zones in the "couch/config.php", which is:
Code: Select all
// 2.
    // Your Time Zone
    // Example values (note how :15, :30, :45 will be entered as .25, .5 and .75 respectively):
    // +12.75 New Zealand (UTC+12:45)
    // +8.75  Australia (UTC+08:45)
    // +5.5   India (UTC+05:30)
    // +1     Germany (UTC+01:00)
    // 0      United Kingdom (UTC±0)
    // -2     Brazil (UTC-02:00)
    // -4.5   Venezuela (UTC-04:30)
    // -6     United States (Central Time) (UTC-06:00)
    // -8     United States (Pacific Time) (UTC-08:00)
    define( 'K_GMT_OFFSET', +5.5 );


If this could be implemented through the couch/config.php, it would be great, as it would solve a lot of hassles (though I cannot think much about multi-lingual sites).

A straightforward implementation as:
Code: Select all
$amount = new \NumberFormatter( 'en_IN', \NumberFormatter::CURRENCY );
return $amount->format( 123456789 );

would output:
₹ 12,34,56,789.00


while for en_DE locale (a list of locale can be found here), it would output:
€123.456.789,00


Making it very easy to handle currency symbols, decimal characters, thousands_separator etc.

Nevertheless, I suppose a small implementation could also come in with the <cms:number_format> tag. Something like the no round-off feature.

Example usage of no round-off
<cms:number_format '21.188' /> // outputs 21.19
<cms:number_format '21.188' round='0' /> // outputs 21.18


If the same tag can have an attribute as pvs_format, where pvs_format could takeon the locale values like en_IN, en_DE, de_DE, etc. and implement the NumberFormatter Class it would be really helpful.

Code: Select all
<cms:number_format '21.188' round='0' pvs_format='en_IN' />


Does it sound useful to others too?

@KK Sir: Could you please have a look at this!

Regards,
GenXCoders
Image
where innovation meets technology
Good Evening to you too, @genxcoders.

Have you checked my repository? I think a function Cms-Fu Funcs » inr-format could be helpful.

Please let me know.
@Bro Anton
I actually didnt. I will check it.
Thanks.

*****

Kudos... this also works... But if this locale formatting comes in it will go a long way i suppose...

Nevertheless, thanks a ton @Bro Anton...
Image
where innovation meets technology
genxcoders wrote: @Bro Anton
I actually didnt. I will check it.
Thanks.

*****

Kudos... this also works... But if this locale formatting comes in it will go a long way i suppose...

Nevertheless, thanks a ton @Bro Anton...


Hahaha, tricked! I actually wrote the func after this topic appeared and you are welcome ☺

:)

I've read about this NumberFormatter Class and it seems cool! It's a pity it requires an extension plus a bunch of dlls on Windows for the extension to work well, as this Stackoverflow answer suggests.
Ya i got to see that by the post timestamp. :)
Image
where innovation meets technology
5 posts Page 1 of 1
cron