CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • How to manage monetary display
Pages: [1]

Author Topic: How to manage monetary display  (Read 3230 times)

hwdornbush

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 0
How to manage monetary display
July 04, 2008, 03:36:32 pm
In the documentation for Settings - Localization, it states:

'Monetary Display - Enter the format for displaying monetary values, i.e. "%c %a"'

I haven't found any documentation on what values, such as %c or %a, are to be used if I want to vary this.

In my case, the default for USD currency is something like $25000.00

and I would like to make it $25,000

I assume that if I understood what the basis was for the %c and %a format strings, I could make this change.

What are the format rules for this field?

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: How to manage monetary display
July 05, 2008, 11:35:33 am
The display of monetary data is driven by two settings.

First, the Monetary Locale setting says how to separate decimal parts, thousands parts, etc. of the amount; changing this setting sets the LC_MONETARY locale and then calls the underlying operating system to format the number according to the given country’s official notation.

Second, the Monetary Display setting tells CiviCRM how to display the amount with regards to the currency symbol. The supported format strings are %a for amount, %c for the currency symbol (for example, $) and %C for the currency ISO code (for example, USD).
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

hwdornbush

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 0
Re: How to manage monetary display
July 05, 2008, 02:58:41 pm
There is only one choice for the Monetary Locale setting: en_US.  In the documentation for "CiviCRM Localisation," it states "The amount of 1234567 dollars and 89 cents will be displayed as '1,234,567.89' with an 'en_US' locale" but my CiviCRM installation (1.9) displays dollars and cents like '1234567.89' that is, without the commas.  I tried to test this on the 2.0 demo system, but the demo account does not have access to civicontributions, so I can't test to see if this is fixed on 2.0.

Am I missing something on how to configure this locale setting so I see the commas?

If I want to remove the "cents" part, where would I go to customize this formatting?

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: How to manage monetary display
July 05, 2008, 08:25:14 pm
Quote from: hwdornbush on July 05, 2008, 02:58:41 pm
There is only one choice for the Monetary Locale setting: en_US.  In the documentation for "CiviCRM Localisation," it states "The amount of 1234567 dollars and 89 cents will be displayed as '1,234,567.89' with an 'en_US' locale" but my CiviCRM installation (1.9) displays dollars and cents like '1234567.89' that is, without the commas.

Hm, this is strange. CiviCRM sets the LC_MONETARY locale and then calls PHP’s money_format() function, which should work if the underlying system is a POSIX one and the support for the en_US locale is enabled.

What system does the CiviCRM installation runs on?

Quote from: hwdornbush on July 05, 2008, 02:58:41 pm
If I want to remove the "cents" part, where would I go to customize this formatting?

You need to hack the CRM_Utils_Money::format() method in CRM/Utils/Money.php
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

hwdornbush

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 0
Re: How to manage monetary display
July 06, 2008, 04:00:38 pm
I set up a simple page in Drupal to test this.  First, I used what you suggested, based on what was in CRM/Utils/Money.php

<?php
 if ( function_exists( 'money_format' ) ) {
print (money_format('%!i', 10000));
} else {print("no money_format");}
?>

and I got
10000.00

I wanted to get rid of the digits to the right of the decimal, so I tried the following:

<?php
 if ( function_exists( 'money_format' ) ) {
print (money_format('%!.0i', 10000));
} else {print("no money_format");}
?>

and the result was
10000

Then I added the setlocale() call:

<?php
 if ( function_exists( 'money_format' ) ) {
setlocale(LC_MONETARY, 'en_US');
print (money_format('%!.0i', 10000));
} else {print("no money_format");}
?>

and now I get
10,000

I don't know where you call setlocale() but it seems to be missing from my implementation.

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: How to manage monetary display
July 06, 2008, 10:24:06 pm
Thanks for the info – we do indeed seem to be missing the setlocale() call in 2.0, but have it in place on trunk (i.e., will be in CiviCRM 2.1).

If I got the above right, it seems setting the Monetary Display option to %!.0i should do the trick for you without any CiviCRM code changes. Am I right?
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

hwdornbush

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 0
Re: How to manage monetary display
July 07, 2008, 10:08:00 am
Unless it changed, the Monetary Display option only allows %a, %c and %C which don't do what I need.  I would be *MUCH* happier if I could put something like %!.0i in this field so I don't have to change CiviCRM.

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: How to manage monetary display
July 07, 2008, 03:12:08 pm
Argh, now that I looked into the code, it seems we parse Monetary Display ourselves, and send a static %!i to money_format(). I created CRM-3287 to track this.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: How to manage monetary display
July 17, 2008, 11:47:55 am
Fixed on trunk, so will be an option in CiviCRM 2.1. :)
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • How to manage monetary display

This forum was archived on 2017-11-26.