Please support more decimal places

Currently I work with large quantities of products with very low prices. For example, I may have 9,000 units with each unit price being $0.0395 (I don’t make the prices).

Any time I try to set a product’s price to $0.0395, it rounds to $0.04 which causes discrepancies.

Is there any way we can resolve this?

I’ll make a PR if no one wants to work on it, I just feel that I may not be up to your standards on code structure and “tidiness.”

Thanks!

Alright, so… again let me repeat the fact that I’m only a hobbyist when it comes to programming, AND this is my first day playing with IP so please bear with me.

So my issue was that when I tried to enter a price that had more than 2 decimal places, it would round up. I deal with a lot of prices that have 3 decimal places, such as $0.0395.

I resolved this by the following:

  1. Updated ip_products:product_price type from decimal(20,2) to float
  2. Edited /application/helpers/number_helper.php

On number_helper.php, below line 25 I added the following:

$decimal_places = (strlen(substr(strrchr($amount, "."), 1)) < 2) ? 2 : strlen(substr(strrchr($amount, "."), 1));

If you notice, it counts the decimals places of $amount and if it’s less than 2, it default to two. If it’s not less than 2, it will return however many decimal places $amount has.

For example, if $amount is 1.10 or 1.1 it will be changed to 1.1 but the line above will still use 2 decimal places. If $amount is something like 12.98765, it will use 5 decimal places.


Then on the if statement at line 28-34, I change it to this:

if ($currency_symbol_placement == 'before') {
    return $currency_symbol . number_format($amount, ($decimal_point) ? $decimal_places : 0, $decimal_point, $thousands_separator);
} elseif ($currency_symbol_placement == 'afterspace') {
    return number_format($amount, ($decimal_point) ? $decimal_places : 0, $decimal_point, $thousands_separator) . '&nbsp;' . $currency_symbol;
} else {
    return number_format($amount, ($decimal_point) ? $decimal_places : 0, $decimal_point, $thousands_separator) . $currency_symbol;
}

I also had to add edit the format_amount function at line 43 with the following:

if ($amount) {
        $CI =& get_instance();
        $thousands_separator = $CI->mdl_settings->setting('thousands_separator');
        $decimal_point = $CI->mdl_settings->setting('decimal_point');
        $decimal_places = (strlen(substr(strrchr($amount, "."), 1)) < 2) ? 2 : strlen(substr(strrchr($amount, "."), 1));

        return number_format($amount, ($decimal_point) ? $decimal_places : 0, $decimal_point, $thousands_separator);
    }
    return null;

That’s what I did for a temporary fix. I’ll create a better way and submit a PR if you guys if you’re okay with this. Now, in the products prices I can use as many decimal places as I’d like:

Opps…

I also had to change another table, ip_invoice_items:item_price

Changed the type from decimal(10,2) to float.

Seems to be working. I’ll check more…

Thank you very much, you did a great job.
If you want i’ll help you with creating a pull-request.

Easiest way I can help is through slack

Are you up for the challenge?

Hello, is this still the only solution to this problem?

@miltonardila There is a pull-request on github, that we’re looking at.
The PR on github isn’t complete, so we can’t merge.
To be continued…