mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-16 15:21:48 +03:00
Special rounding precision for poll percentage
This commit is contained in:
parent
c3bbd04e77
commit
65c2fb3648
1 changed files with 13 additions and 2 deletions
|
@ -923,6 +923,16 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
|
|||
|
||||
const expiresAtDate = !!expiresAt && new Date(expiresAt);
|
||||
|
||||
const pollVotesCount = votersCount || votesCount;
|
||||
let roundPrecision = 0;
|
||||
if (pollVotesCount <= 1000) {
|
||||
roundPrecision = 0;
|
||||
} else if (pollVotesCount <= 10000) {
|
||||
roundPrecision = 1;
|
||||
} else if (pollVotesCount <= 100000) {
|
||||
roundPrecision = 2;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
class={`poll ${readOnly ? 'read-only' : ''} ${
|
||||
|
@ -932,9 +942,10 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
|
|||
{voted || expired ? (
|
||||
options.map((option, i) => {
|
||||
const { title, votesCount: optionVotesCount } = option;
|
||||
const pollVotesCount = votersCount || votesCount;
|
||||
const percentage =
|
||||
Math.round((optionVotesCount / pollVotesCount) * 100) || 0;
|
||||
((optionVotesCount / pollVotesCount) * 100).toFixed(
|
||||
roundPrecision,
|
||||
) || 0;
|
||||
// check if current poll choice is the leading one
|
||||
const isLeading =
|
||||
optionVotesCount > 0 &&
|
||||
|
|
Loading…
Add table
Reference in a new issue