Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: format decimal precision problem #172

Conversation

FibrinLab
Copy link

Resolves #77

Offering a solution to the precision problem @0x4007 @gentlementlegen

By scaling, flooring, and then displaying, you retain the intended precision without triggering floating-point issues

@@ -127,7 +127,7 @@ export class ContentEvaluatorModule implements Module {
currentComment.score = {
...(currentComment.score || { multiplier: 0 }),
relevance: new Decimal(currentRelevance).toNumber(),
reward: currentReward.toNumber(),
reward: new Decimal(currentReward).mul(100).round().div(100).toNumber(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplying and dividing seems wrong. It just cancels itself out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0x4007 It doesn't because of the round, so this basically is a 3 decimal rounding operation. But I don't think this is necessary because Decimaljs can handle an "infinite" amount of decimals. currentReward should be a finite number during all operations.

Copy link
Author

@FibrinLab FibrinLab Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, are you suggesting that rounding should be avoided altogether to keep maximum precision until the final display stage? I understood from your comment that decimal.js can handle high precision throughout all operations without the need for intermediate rounding. If so, would it be preferable to apply formatting only at the end for display purposes, rather than during calculations? @gentlementlegen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decimal is not properly displayed
3 participants