Round off Percentage

QuestionsRound off Percentage
ChrisW asked 7 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 7 years ago

Hello,
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 7 years ago

Bah, makes sense. Thanks for the swift response.

Your Answer

13 + 17 =

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?