Steem Reputation Format Function in PHP
- Time:2020-09-08 11:08:55
- Class:Weblog
- Read:28
On Steem Blockchain, the reputation can be formatted in a logarithmetic (base 10) scale. Given recently, my PR to fix the reputation formatter in SteemJS is merged, I also translate this to PHP which I need.
1 2 3 4 5 6 7 8 9 | function formatReputation($rep) { if (!$rep) return 25; $neg = $rep < 0; $rep = (string)$rep; $rep = $neg ? substr($rep, 1) : $rep; $v = log10(($rep > 0 ? $rep : -$rep) - 10) - 9; $v = $neg ? -$v : $v; return round($v * 9 + 25, 3); } |
function formatReputation($rep) { if (!$rep) return 25; $neg = $rep < 0; $rep = (string)$rep; $rep = $neg ? substr($rep, 1) : $rep; $v = log10(($rep > 0 ? $rep : -$rep) - 10) - 9; $v = $neg ? -$v : $v; return round($v * 9 + 25, 3); }
Some Example usages:
1 2 3 4 5 6 | echo formatReputation(95832978796820) . "\n"; echo formatReputation(10004392664120) . "\n"; echo formatReputation(30999525306309) . "\n"; echo formatReputation(-37765258368568) . "\n"; echo formatReputation(334486135407077) . "\n"; echo formatReputation(0) . "\n"; |
echo formatReputation(95832978796820) . "\n"; echo formatReputation(10004392664120) . "\n"; echo formatReputation(30999525306309) . "\n"; echo formatReputation(-37765258368568) . "\n"; echo formatReputation(334486135407077) . "\n"; echo formatReputation(0) . "\n";
The above PHP code should output the following values (you can use them to unit test the function):
69.834 61.002 65.422 -16.194 74.719 25

php
–EOF (The Ultimate Computing & Technology Blog) —
Recommend:Why conducting a website audit is important
How to Write a Great Blog Post for a Global Audience
Top Reasons Why Your Blog Sucks at Making Money (and How to Fix
How To Write A Great Product Placement Blog Post
Structured Data for SEO Blogging
5 Ways a Blog Can Help Your Business Grow
How to Create Killer Project Proposals to Land Five-Figure Blogg
Why Local SEO Is the Best Option for Promoting Your Website
Greedy Algorithm to Group the Numbers/Items Given the Group Size
Design A Leaderboard using Priority Queue, Hash Map (unordered_m
- Comment list
-
- Comment add