Skip to content

Fix confidence percentage precision — show integers only #163

Description

@KiwiGaze

Problem

formatConfidence in apps/web/components/parsing/utils.ts can produce decimal percentages due to floating-point arithmetic. For example, a confidence of 0.876 becomes 87.6% instead of 88%.

The current implementation multiplies by 100 and strips trailing zeros, but preserves non-zero decimal digits:

const percentage = confidence * 100;
const normalized = percentage.toString();
const trimmed = normalized.includes(".")
  ? normalized.replace(/\.0+$/, "").replace(/(\.[0-9]*[1-9])0+$/, "$1")
  : normalized;
return `${trimmed}%`;

Floating-point multiplication can also introduce artifacts (e.g., 0.1 * 100 = 10.000000000000002), and the current regex only strips trailing zeros — not all decimal digits.

Expected behavior

Confidence percentages should always display as integers (e.g., 88%, 100%, 75%).

Affected components

  • apps/web/components/parsing/event-card.tsx — confidence badge
  • apps/web/components/parsing/task-card.tsx — confidence badge

Suggested fix

Replace the string manipulation with Math.round:

export function formatConfidence(confidence: number | null | undefined): string {
  if (typeof confidence !== "number") return "–";
  return `${Math.round(confidence * 100)}%`;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions