HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Is there a way to only show integer percentage but not float value?
vanillawhisky
New
in Feedback
Hello,
At the moment it shows float percentage value , like 100.00% for vote counts. Is it possible not to include values after decimal , like 100% ?
Thank you in advance
Tagged:
0
Comments
Do you see this line?
https://github.com/hgtonight/Plugin-DiscussionPolls/blob/master/views/results.php#L45
$Percentage = ($Question->CountResponses == 0) ? '0.00' : number_format(($Option->CountVotes / $Question->CountResponses * 100), 2);
the 2 at the end stands for number of decimal places.
you would also probably want to change 0.00 to 0
http://php.net/manual/en/function.number-format.php
the second parameter controls the numbers beyond the decimal point. You can remove the second argument.
see how the removal of the , 2 removes the decimal point and the 2 numbers following the decimal point.
http://www.w3schools.com/php/showphp.asp?filename=demo_func_string_number_format
http://www.w3resource.com/php/function-reference/number_format.php
you could replace the view.
Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.
Thanks for your comment.
I tried to rewrite the function
and put in themehook file but (i guess) since this is not a public function, this doesnt work.
Is there a way to do without directly changing in plugins itself?
Thank you!!!
I'd either ask the plugin author to change or allow for it, or consider modifying it via Javascript after it's output.
It cannot be overridden as currently implemented.
Yes.
like I said you could change the VIEW for this particular plugin if you don't want to modify the plugin itself. This is not a general technique for all plugins.
changing the view "hiding" or overriding changes in the theme folder or changing a bootstrap function can get you in as much trouble or more than just forking and changing the darn plugin. The view or function can be stale, a security flaw may be fixed and you will happily upgrade your plugin without a worry, because you thought since you didn't directly modify the plugin you are home free. Point being, know what you are doing, keep it simple. Sometimes hundreds of code gyrations to keep a community plugin unchanged is a bit overdone in my mind and prone to just as much problems as directly making a simple change and documenting it for the other admins.
or propose a change via a github to just have a changeable variable thru translation or config for the second argument in the percentage code for the next update of the plugin.
copy
/plugins/DiscussionPolls/views/results.php to ....
lets say your theme is called bittersweet
/themes/bittersweet/views/plugins/DiscussionPolls/results.php
make the change to the results.php in bittersweet/views/plugins/DiscussionPolls/
change
to
either
or
Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.
I love to say that: it can be done in this case!
This is the place where the view "results.php" is included:
But it is not simply included, it uses a helper function instead:
You can see in the functions documentation how you can override the view. You need a custom theme for that, though.
All credits go to @x00 https://vanillaforums.org/discussion/comment/225740#Comment_225740
@R_J - I provided the complete step-by-step solution. thanks for echoing an abridged version
Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.
Oops! Last time I've loaded the discussion there have been no answers.
But at least it has given the credits to the correct person.
I've tried to save my draft and reload the discussion prior to posting to prevent that type of mishap. but it can happen.
yes nice idea by x00 otherwise the snippet would have probably never have found its way into the author's plugin code.
Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.
@River and @R_J
Thanks guys, it works.
and thank you everyone for help.
u guys rocks.