Negative value (Currency)

QuestionsNegative value (Currency)
Fabio Martins asked 6 years ago

Hi Sir,

Is it possible format a currency negative value to:

(1.000,00) and not -1.000,00

My column code:

//COLUNA DO SALDO
$col = array();
$col["title"] = "Saldo (R$)";
$col["name"] = "saldo";
$col["align"] = "right";
$col["formatter"] = "currency";
$col["formatoptions"] = array("prefix" = "");

And negative values are displayed (for example): -234,00

Thank you!!!
Fábio Martins

3 Answers
Abu Ghufran answered 6 years ago

You might have to use custom formatter, e.g.

in php code …

$col = array();
$col["title"] = "Price";
$col["name"] = "price";
$col["width"] = "50";
$col["editable"] = true;
$col["formatter"] = "function(cellvalue, options, rowObject){ return formatPrice(cellvalue, options, rowObject);}";

and in html …

<script>
function formatPrice(cellvalue, options, rowObject)
{
if (cellvalue < 0)
return '('+cellvalue+')';
else
return cellvalue;
}
</script>
<div style="margin:10px">
<?php echo $out?>
</div

Fabio Martins answered 6 years ago

Hi Sir!

Your example sometimes works (it returns currency value formatted), but in other no (it returns undefined)!
I'm searching possible erros on my php code.

Congratulations! PHPgrid is very good!!!

Thank you!
Fábio Martins

Abu Ghufran answered 6 years ago

Hello,

You might need to put an undefined check in JS.

<script>
function formatPrice(cellvalue, options, rowObject)
{

if (typeof(cellvalue) == "undefined")
return 0;

if (cellvalue < 0)
return '('+cellvalue+')';
else
return cellvalue;
}
</script>

Your Answer

0 + 14 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

We are sorry that this post was not useful for you!

Let us improve this post!