2

Based on this year 2008 thread and a few earlier threads on civi.stackexchange regarding the matter. Now (CiviCRM 5.56.2), when "Monetary Amount Display" on civicrm/admin/setting/localization?reset=1 is deprecated and gone, how do we, say, remove decimals from currency display, apart from altering CRM_Utils_Money?

1

1 Answer 1

1

While not a supported option, theoretically you can replace \Civi::$statics[$cacheKey]; from https://github.com/civicrm/civicrm-core/blob/b0fff1c64cf3dd2e40b248b3b067ca30de09aeee/Civi/Core/Format.php#L220, probably in hook_civicrm_config in an extension, with a modified $formatter object that does what you want.

e.g. in hook_civicrm_config

$cacheKey = <figure out cachekey>
$formatter = \Civi::$statics[$cacheKey];
// make some changes to $formatter here
\Civi::$statics[$cacheKey] = $formatter;

But it would be nicer if there was a supported way to change the parameters that the formatter object uses.

5
  • Wouldn't it be easier to have a copy of Money.php in custom php directory and alter getCurrencyPrecision() ?
    – yurg
    Commented Jan 6, 2023 at 21:21
  • It makes upgrades harder if you need to sync changes every time, but yes that should work too.
    – Demerit
    Commented Jan 6, 2023 at 21:39
  • Indeed; I was thinking about a tiny extension which would extend the CRM_Utils_Money class, just not sure which hook to use.
    – yurg
    Commented Jan 6, 2023 at 22:58
  • 1
    If we assume the target audience for customizing is developers, then I think the solution to that would be to change this line in core so that it acts like a service, similar to the logger, so that you could replace it like the way monolog does.
    – Demerit
    Commented Jan 6, 2023 at 23:33
  • That would replace the entire Format class not just the money formatter, but it's the same idea, you'd extend it, and just override the part you need.
    – Demerit
    Commented Jan 6, 2023 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.