Special rounding precision for poll percentage

pull/20/head
Lim Chee Aun 2022-12-22 14:59:36 +08:00
rodzic c3bbd04e77
commit 65c2fb3648
1 zmienionych plików z 13 dodań i 2 usunięć

Wyświetl plik

@ -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 &&