This topic is locked

conditional decimal places

9/21/2009 11:16:34 AM
PHPRunner General questions
M
mfero author

PHPRunner 5.1
When I use currency as a fihttp://eld property, it defaults to two decimal places.
Problem: I have one field which, although currency, is always a whole number.
My Solution: By editing locale.php and changing $locale_info["LOCALE_ICURRDIGITS"]="2" to $locale_info["LOCALE_ICURRDIGITS"]="0", changing the field property to number and inserting a $ immediately to the left of the field, I can achieve the desired result.
Unfortunately there are six fields, one of which always displays but the others don't always have data. This leaves me with $ signs in otherwise empty fields. I would prefer not to have the $'s display in the empty fields.
Question: is it possible to use a custom property which would accomplish the desired outcome and, if so, any ideas what $value = ____ {$value}; would be?
TIA

J
jsuisman 9/21/2009



PHPRunner 5.1
When I use currency as a fihttp://eld property, it defaults to two decimal places.
Problem: I have one field which, although currency, is always a whole number.
My Solution: By editing locale.php and changing $locale_info["LOCALE_ICURRDIGITS"]="2" to $locale_info["LOCALE_ICURRDIGITS"]="0", changing the field property to number and inserting a $ immediately to the left of the field, I can achieve the desired result.
Unfortunately there are six fields, one of which always displays but the others don't always have data. This leaves me with $ signs in otherwise empty fields. I would prefer not to have the $'s display in the empty fields.
Question: is it possible to use a custom property which would accomplish the desired outcome and, if so, any ideas what $value = ____ {$value}; would be?
TIA



Michael,
Put one of the following lines in the custom box.



$value = number_format($value);//No decimal places

$value = number_format($value,1);//1 decimal place

$value = number_format($value,2);//2 decimal places



You could also add the dollar sign to this with:



$value = "\$".number_format($value);//no decimal places with dollar sign.


Good luck,
Jarred

M
mfero author 9/22/2009



Michael,
Put one of the following lines in the custom box.



$value = number_format($value);//No decimal places

$value = number_format($value,1);//1 decimal place

$value = number_format($value,2);//2 decimal places



You could also add the dollar sign to this with:



$value = "\$".number_format($value);//no decimal places with dollar sign.


Good luck,
Jarred

M
mfero author 9/22/2009





Jared:
This just about does it, especially "$value = "\$".number_format($value);//no decimal places with dollar sign" but when there is no value in the table it renders $0. Is it possible to have it not show anything unless there is a value to display?
Thank you!

J
jsuisman 9/22/2009

Michael,
Although I have never tried this with phprunner, I would say that the ternary operator would work for you here:



$value = (number_format($value) !== 0 ? "\$".number_format($value):"");


I did it like this because I'm not sure what phprunner would use for a default empty value. Let me know if it works ( or doesn't ).
Good luck,
Jarred

M
mfero author 9/23/2009



Jared:
This just about does it, especially "$value = "\$".number_format($value);//no decimal places with dollar sign" but when there is no value in the table it renders $0. Is it possible to have it not show anything unless there is a value to display?
Thank you!

M
mfero author 9/23/2009



Michael,
Although I have never tried this with phprunner, I would say that the ternary operator would work for you here:



$value = (number_format($value) !== 0 ? "\$".number_format($value):"");


I did it like this because I'm not sure what phprunner would use for a default empty value. Let me know if it works ( or doesn't ).
Good luck,
Jarred


Unfortunately, this still returns the $0. If it's not possible, I suppose I can live with two decimal places.
Thank you!

J
Jane 9/23/2009

Michael,
here is a sample:

if ($value)

$value = str_format_currency(number_format($value));
J
jsuisman 9/23/2009



Michael,
here is a sample:

if ($value)

$value = str_format_currency(number_format($value));




Thanks for chiming in Jane, wasn't thinking it was a boolean thing.
Michael, this will work for you with dollar sign:



if ($value)

$value = "\$".number_format($value);


Back in office, tested and working.
Jarred

M
mfero author 9/23/2009



Thanks for chiming in Jane, wasn't thinking it was a boolean thing.
Michael, this will work for you with dollar sign:



if ($value)

$value = "\$".number_format($value);


Back in office, tested and working.
Jarred


It works!
Thank you very much.