Created
May 18, 2018 19:04
-
-
Save xnau/a2be573c34f66feba36236203a581c2d to your computer and use it in GitHub Desktop.
Demonstrates how to show decimal numbers using comma as the separator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: PDB Comma Decimal Separator Display | |
* Description: alters the display of decimal numbers to use comma as the decimal separator, and point as the thousands separator | |
*/ | |
add_filter('pdb-before_display_form_element', 'xnau_show_comma_decimals', 10, 2 ); | |
function xnau_show_comma_decimals( $display, $field ) | |
{ | |
// we are only modifying these form element types | |
if ( $field->form_element === 'decimal' || $field->form_element === 'currency' ) { | |
// count the number of decimal digits in the number | |
$decimals = strlen( strstr( $field->value, '.' ) ) -1; | |
// this function formats the number using comma for the decimal separator and dot for the thousands separator | |
$display = number_format( $field->value, $decimals, ',', '.' ); | |
} | |
return $display; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment