• Resolved bittolas

    (@bittolas)


    First of all i wanted to praise you for this great work you have here. The plugin is really good!

    I’m kinda new to wordpress so my doubt is probably something stupid from my part…

    I have this formula =A1/A2 since it is not an exact the ouput is something like 0,123456789012. Is there any way to limit to something like 0,123?
    I tried using css but it only limited the width of the column and the number goes out of the column.

    Sorry for my bad english
    Thanks!

    http://ww.wp.xz.cn/extend/plugins/tablepress/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your question. Nice to hear that you like the plugin so much!

    This is more of a mathematical problem, so I suggest to just round the result of the formula:

    =ROUND(A1/A2,3)

    The “3” indicates that you want three digits after the comma.

    Regards,
    Tobias

    Thread Starter bittolas

    (@bittolas)

    Thanks for the quick response.
    That worked as intended however sorting went incorrect.

    [table id=1 row_order="sort" row_order_sort_column="F" row_order_sort_direction="DESC" /]

    I have this and my last 4 rows have this values: 0,256 0,37 0,25 0,6
    Any way to correct this?

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    good to hear that this worked.

    Are those numbers really with a comma? For the sorting, they should use a period (.) as the decimal delimiter, I think.
    Is the sorting working correctly, if you use integer numbers?

    Can you please post a link to the page with this table?

    Regards,
    Tobias

    Thread Starter bittolas

    (@bittolas)

    Hey.
    With integer everything goes ok.

    Sorting goes normally if every value has the same number of digits after comma but if they have less they go to the end/start.

    This is the table: Link

    I believe the problem is the comma. Any way to change it automatically?

    Thanks!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for that extra info! I will look into it, to maybe find a solution to automatically replace the comma.

    Meanwhile, you should add this to your “Custom CSS”:

    .tablepress [class*="column"] + [class*="column"]:last-child {
      float: none;
    }

    That will fix that wrong layout in the head of the last column, which is caused by some of your theme CSS.

    Regards,
    Tobias

    Thread Starter bittolas

    (@bittolas)

    Thanks!

    Since i have some programing knockledge (not in php) I checked the code of the extension row order.

    I don’t know if it will be usefull to you but i changed the function compare_rows to this:

    public function compare_rows( $a, $b ) {
    		return strnatcasecmp( number_format($a[ self::$sort_column ], 3, '.', ''), number_format($b[ self::$sort_column ], 3, '.', '') );

    Php Manual: Link

    It seems to be working to me.

    Hope it helps 🙂

    Keep the good work!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    nice, that looks like a good solution! I’ll see if this works universally and then add it to the Extension. Thanks!

    Regards,
    Tobias

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    after looking into the formulas a little bit more, I’m actually confused, how you ended up with commas instead of periods as the decimal separators in your formula results.

    Does =A/B really result in a number that has a comma and not a period?

    Regards,
    Tobias

    Thread Starter bittolas

    (@bittolas)

    I use the number_format to change the value from commas to period just before the comparison in the function compare_rows so no value from the table is changed permanently.

    I changed nothing that has to do with formula results.

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    yes, I understand that part.
    But I’m curious why you even have commas in the cells. Where are those coming from? Are these in the entered values, or are they in the results of formulas, too, like the output of a formula like =A1/A2?

    Regards,
    Tobias

    Thread Starter bittolas

    (@bittolas)

    Sorry I’m not very good at explaining

    They are 100% the results from the formula.

    The thing is I pick the value $a[ self::$sort_column ] and change it with the function but it’s not saved. The value in the table continues with commas but during the comparison the value that is used it’s with period.

    It’s like I get a temporary copy of the value with period instead of comma.

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    yes, that’s correct. That code only changes the value from , to . during the sorting. Would you like that to be permanent, so that the final output also uses periods?

    And I’m still confused about why you actually get the commas from the formulas… This does not happen on my test sites.
    Would it maybe be possible that I can take a look at this directly on your site, and maybe run a few tests in the WP admin area? I’d like to find out what’s going on here. Can you therefore please contact me via email (the address is in the main plugin file “tablepress.php”)?

    Thanks!
    Tobias

    Thread Starter bittolas

    (@bittolas)

    For me is ok getting commas, I’m from Portugal and we actually use commas for decimal numbers. I believe that can be the reason since my wordpress is pt-pt version.

    I will try to talk with my partner as soon as possible and contact you 🙂

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    yes, that might be the reason, but it’s probably a server setting and not the language of the WordPress version. I’ve tried this on a test server with a German WordPress (we also use the comma for this in Germany), but the formulas would only have periods. So, not sure why this happens.

    Yes, it would be great if you could contact me after talking to your partner. Thanks!

    Best wishes,
    Tobias

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Limiting output from formula’ is closed to new replies.