Get percentage

7 posts / 0 new
Last post
Ahmed
Offline
Joined: 09/20/2017 - 05:45
Get percentage

Hi,
I need to do a calcul to get a result in percentage % , so is there any function or script to do it ?
as alternative solution what I'm doing is : creating new numeric field and I insert this fomule : (Column A / Column B )*100  
Thank you.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Ahmed,

I would just do it the way you said, create a virtual field with that formula.  You can easily incorporate it into a script if you want.

Thanks

Brian

Ahmed
Offline
Joined: 09/20/2017 - 05:45

Hi Brian;
I found also this; but with character type :  @Insert(@Str(( (A /B) * 100 );0;2);6 ; "%") 
As you can see it in the snapshot,
Thank you Brian.
 

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Ahmed,

I would probably change your equation if you expect to have negative percentages or over 100% as the % is being inserted in position 6 so it is possible that it might get inserted before the last number.  I would use:

(@Str(( (A /B) * 100 );0;2) + "%"

This way you are always sure that the last character is the percentage.

Ahmed
Offline
Joined: 09/20/2017 - 05:45

Yes Bian, it's more accurate.
and if I want to convert it to numeric field is there any equation to do it ?
Thank you.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Ahmed, if you want to convert it to numeric you need to first either not add or remove the % and then use the @val() function.  That will take a string and change it to a number.

Ahmed
Offline
Joined: 09/20/2017 - 05:45

Okay, now; I have the choice between two function.
Thank you Brian for your advise.