Round off Percentage

QuestionsRound off Percentage
ChrisW asked 5 years ago

I am using the following Column Formater from the guide
$col = array();
$col[“name”] = “Margin”;
$col[“formatter”] = “function(cellval,options,rowdata){ return cellval*100+’%’; }”;
$col[“unformat”] = “function(cellval,options,cell){ return cellval.replace(‘%’,”)/100; }”;
$cols[] = $col;
The percentage values I am getting are like “39.253121532461322214%”
I have tried to use round(), but the grid just shows “loading…” and never does. C
Can you advise?

1 Answers
Abu Ghufran Staff answered 5 years ago

This is JS code so you need to use Math.round(value, precision)
$col[“formatter”] = “function(cellval,options,rowdata){ return Math.round(cellval*100,2)+’%’; }”;

Abu Ghufran - Dev Team
Grid 4 PHP Framework
ChrisW replied 5 years ago

Bah, makes sense. Thanks for the swift response.

Your Answer

2 + 16 =

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 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

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

Let us improve this post!

Tell us how we can improve this post?