Formatting Numeric Values in Input

Any tips and tricks that has to with the ADDT that doesn't fit into one of the other categories
energylevels2012
Posts: 58
Joined: 2012-07-22 16:41

Formatting Numeric Values in Input

Post by energylevels2012 » 2014-06-01 03:43

Doesn't seem to be a built in way to handle how numbers are displayed/formatted in ADDT?

I have a numeric value want to display in input field with thousand comma separators like 10,000 .... can format value for display in php number_format() for display but how then how do you clean the value before inserting into mysql again?

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: Formatting Numeric Values in Input

Post by Fred » 2014-06-01 09:37

A bit of hand coding will do the trick.
Refer to this article as a starting point http://www.interaktonline.info/article/ ... email.html

Then your code will be something like this

Code: Select all

$string = str_replace(',', '', $string);

energylevels2012
Posts: 58
Joined: 2012-07-22 16:41

Re: Formatting Numeric Values in Input

Post by energylevels2012 » 2014-06-02 03:46

Thanks sorted

Code:

//start Format_Prices trigger
function Format_Prices(&$tNG) {
$tNG->setColumnValue("Cost_Price", trim(str_replace(',','',$tNG->getColumnValue('Cost_Price'))));
}
//end Format_Prices trigger


Trigger 'BEFORE' code for insert and update in appropriate sections:

$ins_valuations->registerTrigger("BEFORE", "Format_Prices", 50);

$upd_valuations->registerTrigger("BEFORE", "Format_Prices", 50);


Input field with number formatted with thousands comma separator:

<input type="text" name="Cost_Price_<?php echo $cnt1; ?>" id="Cost_Price_<?php echo $cnt1; ?>" value="<?php echo number_format($row_rsvaluations['Cost_Price']); ?>" size="10" />

Post Reply