Results 1 to 7 of 7

Thread: Decimal precision and currency

  1. #1
    Iggby's Avatar
    Iggby is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    Huntingtonton Beach, Ca
    Posts
    101

    Default Decimal precision and currency

    I am having a problem with differing decimal precision in different views.

    Specifically when using a currency field in a custom module, the edit screen and the detail screen both show the number in the proper currency format of X,XXX.XX When on the list view however the number is displayed as X,XXX.XXXXXX Can anyone suggest a solution to this problem. I would like to display the number in the proper 2 decimal precision format for US currency.

    Also I have a couple of decimal fields with precision of (3) and max size (8) however when viewing a number such as 5.375 the number is being rounded up to 5.38. Shouldn't the precision of (3) set the field to display a number with a precision of (3) as well?

    These issues are causing many problems with my installation as consistency in display of currency and decimals is a must. Any suggestions on a fix would be greatly appreciated. The module in question was created with module builder and my version is 5.0.0b.

  2. #2
    dpatech is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    NC
    Posts
    287

    Default Re: Decimal precision and currency

    To display currency properly in your listview, add the "currency_format" attribute as shown below. This was taken from the Opportunity module list view definition.

    PHP Code:
    'AMOUNT_USDOLLAR' => array(
    'width'   => '10'
    'label'   => 'LBL_LIST_AMOUNT',
    'align'   => 'right',
    'default' => true,
    'currency_format' => true,
        ), 
    Not sure about decimal precision otherwise, will take a look and see what can be done.
    - Sugar Team
    dpa Technology LLC
    e-mail: dpaDeveloper@dpatechnology.com
    web: http://www.dpatechnology.com

  3. #3
    Iggby's Avatar
    Iggby is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    Huntingtonton Beach, Ca
    Posts
    101

    Default Re: Decimal precision and currency

    Thanks far the response, but it isn't changing the format.

    There are still 6 places in the display after the decimal point after adding 'currency_format' => true, to the listviewdefs.php file of the module in question.

    Did I understand your post correctly?

  4. #4
    dpatech is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    NC
    Posts
    287

    Default Re: Decimal precision and currency

    I forget to mention that Sugar caches the templates so you will ned to go into Admin -> Repiar ->Clear Templates for the module in question. Hopefully that will do the trick for this particular issue. They have also added a new check under Admin->System Settings. The checkbox is named "Developer Mode". If you check this it will never cache the templates. This works well while developing but slows down performance on a production server.
    - Sugar Team
    dpa Technology LLC
    e-mail: dpaDeveloper@dpatechnology.com
    web: http://www.dpatechnology.com

  5. #5
    Iggby's Avatar
    Iggby is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    Huntingtonton Beach, Ca
    Posts
    101

    Default Re: Decimal precision and currency

    Again thanks for the help dpatech. On your suggestion I did try clearing the cache, I had done a total repair earlier and neither worked in the end. I did finally find a solution. I still suspected the problem was somehow related to caching since this was the only thing that made any sense, so I went into studio and removed the field from the list view and then view it to make sure it was removed. Then I went back into the studio and put the field back in. When I viewed it this time it finally displayed properly.

    Another related question. As I am still developing this module I am wondering, when I go back into module builder will it overwrite the change that was just made?

    I am still trying to find a solution to the decimal precision question so if anyone has any ideas please do respond.

  6. #6
    jasminecameron is offline Junior Member
    Join Date
    Oct 2008
    Posts
    1

    Default Re: Decimal precision and currency

    Tuse Locale::Currency::Format;

    $amt = currency_format('USD', 1000); # => 1,000.00 USD
    $amt = currency_format('EUR', 1000, FMT_COMMON); # => EUR1.000,00
    $amt = currency_format('USD', 1000, FMT_SYMBOL); # => $1,000.00

    $sym = currency_symbol('USD'); # => $
    $sym = currency_symbol('GBP', SYM_HTML); # => £

    $decimals = decimal_precision('USD'); # => 2
    $decimals = decimal_precision('BHD'); # => 3

    $thou_sep = thousands_separator('USD'); # => ,
    $thou_sep = thousands_separator('EUR'); # => .

    $dec_sep = decimal_separator('USD'); # => .
    $dec_sep = decimal_separator('EUR'); # => ,

    currency_set('USD', '#.###,## $', FMT_COMMON); # => set custom format
    currency_format('USD', 1000, FMT_COMMON); # => 1.000,00 $
    currency_set('USD'); # => reset default format

    Examlpe
    Total: <% 123456789, 'eur' |c %>

    <%init>
    use Locale::Currency::Format;

    $m->interp->set_escape(c => \&escape_currency);

    sub escape_currency {
    my ($amt, $code) = ${$_[0]} =~ /(.*?)([A-Za-z]{3})/;
    ${$_[0]} = currency_format($code, $amt, FMT_HTML);
    }
    </%init>
    -----------------------------------
    Jasmine


    Guaranteed ROI

  7. #7
    aaguilera is offline Member
    Join Date
    Jan 2009
    Posts
    5

    Thumbs up Re: Decimal precision and currency

    Quote Originally Posted by Iggby View Post
    Again thanks for the help dpatech. On your suggestion I did try clearing the cache, I had done a total repair earlier and neither worked in the end. I did finally find a solution. I still suspected the problem was somehow related to caching since this was the only thing that made any sense, so I went into studio and removed the field from the list view and then view it to make sure it was removed. Then I went back into the studio and put the field back in. When I viewed it this time it finally displayed properly.

    Another related question. As I am still developing this module I am wondering, when I go back into module builder will it overwrite the change that was just made?

    I am still trying to find a solution to the decimal precision question so if anyone has any ideas please do respond.
    You are amazing. I had the same issue with formatting my custom currency fields in the list view, then I tried what you suggested from the studio removing the fields first and putting them back again available for users, and it work perfectly. Are you still having the issues with the decimals? I had the same issues as well ,but only in the list view section. After I did what I just have explained, everything when back to normal.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •