• Resolved canenero

    (@canenero)


    Hello, first of all thank you for your awesome plugin.
    I think that there could be a problem when importing numbers with this example format in the plugin settings: 15.000,0
    If i set the comma as separator for decimal, it doesen’t load the numbers correctly.
    Is better to explain with an example:
    If in the excel i have this number: 890.765,9
    and i import that cell with wpdatatables with 1 decimal place, the output is 890,8 (rounded).
    If i set the comma as separator for decimal (so 15,000.0 in the settings), the number is correctly imported in this way: 890,765.9
    Am i missing something?
    Thank you

    • This topic was modified 4 years, 7 months ago by canenero.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi there, I think I’ve got the same issue. I’m trying to import this number 112.355,738 from Excel in the wpData Table, and the imported result is 112,4 if the column data type is set to “float” and the number format in the plugin settings is “15.000,0” (the format that I need).

    The importing seems to work properly only if I change the number format settings with “15,000.0”, so that the result in the wpDataTable is 112,355.7 but that is not our conventional formatting system. ( we’re based in Italy).

    Same result if I set the column data type as “string” : I’ve got 112.355,738 in the Excel and 112,355.7 in the wpDataTable, but I’d need the same 112.355,738 in the wpDataTable as well (with comma separator for decimals and dot separator for thousands).

    Any help will be greatly appreciated!
    Thank you

    Plugin Author wpDataTables

    (@wpdatatables)

    Hello guys.

    We have an issue with the import regarding the number format, and our developers are working on resolving it for our next update.

    We apologize for the inconvenience this may have caused, but as @silvianuciforo mentioned – the workaround that you can use for now is changing the number format in the plugin. It’s not a perfect solution, but at the moment it’s a solution that works.

    Also, there’s another fix you guys can try. Please go to wp-content/plugins/wpdatatables/source/class.wpdatatable.php and on line 1228 you will find this:

    $dataRow[$key] = str_replace(',', '.', str_replace('.', '', $dataRow[$key]));

    Replace it with this:

    $convertToFloat = (float)(str_replace(',', '.', str_replace('.', '', $dataRow[$key])));
    if ($convertToFloat > 999){
        $dataRow[$key] = str_replace(',', '.', str_replace('.', '', $dataRow[$key]));
    } else {
        $dataRow[$key] = str_replace(',', '.',  $dataRow[$key]);
    }

    This only works for the display, but the filters continue to work as they worked before because the filtering of numbers is specific. Our developers will test this thoroughly before adding it to the update, so please save my response in case it doesn’t make it into our next update, so you can go back into these files and make these changes again.

    Please note that this fix applies to the Lite version of the plugin – if you’re using the full version, please note that we can’t provide support for it on this forum, so we’ll ask you to open a ticket on our official support platform if you’re using the full version.

    Kind regards

    Thread Starter canenero

    (@canenero)

    Hello, i’ve tried your solution but the output is the same.
    The number is rounded and with the comma.
    The code you provided must be inside the if bracket?
    I have this output now:

         
    if (!in_array($wdtParameters['tableType'], array('mysql', 'manual')) && count(array_intersect(array('float', 'int'), $wdtColumnTypes))) {
                $numberFormat = get_option('wdtNumberFormat') ? get_option('wdtNumberFormat') : 1;
                foreach ($wdtColumnTypes as $key => $columnType) {
                    if ($columnType === 'float') {
                        foreach ($this->_dataRows as &$dataRow) {
                            if ($numberFormat == 1) {
             		$convertToFloat = (float)(str_replace(',', '.', str_replace('.', '', $dataRow[$key])));
    			if ($convertToFloat > 999){
        				$dataRow[$key] = str_replace(',', '.', str_replace('.', '', $dataRow[$key]));
    				} else {
        				$dataRow[$key] = str_replace(',', '.',  $dataRow[$key]);
    				}               
                            } else {
                                $dataRow[$key] = str_replace(',', '', $dataRow[$key]);
                            }
                        }
                    }
    

    Thank you

    Plugin Author wpDataTables

    (@wpdatatables)

    Hello again.

    Yes, this should’ve fixed the issue.

    We saw you opened a ticket on our official support platform, and our agents forwarded the issue to our development team.

    As soon as they respond we’ll update you in the ticket, and in this forum as well, so the resolution is visible to all.

    Sorry for the delay.

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

The topic ‘Problem when importing numbers with specific format’ is closed to new replies.