Skip to content

Instantly share code, notes, and snippets.

@xnau
Created May 18, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/a2be573c34f66feba36236203a581c2d to your computer and use it in GitHub Desktop.
Save xnau/a2be573c34f66feba36236203a581c2d to your computer and use it in GitHub Desktop.
Demonstrates how to show decimal numbers using comma as the separator
<?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