Repository navigation
feat: enhance Amount class with Big.js integration - #73
Merged
Merged
Conversation
Part of #63, Closes #64 Changes: - Integrate Big.js for precise decimal calculations - Add serialization: toJSON() / fromJSON() - Add toDisplayString() for locale-aware formatting - Add toDecimals() for precision conversion - Add withAsset() for asset integration - Add percent(), mod(), abs(), neg() operations - Add isAmount() type guard and toAmount() helper API additions: - Amount.fromJSON(json): Deserialize from JSON - amount.toJSON(): Serialize to JSON - amount.toDisplayString({ locale, fractionDigits }) - amount.toDecimals(newDecimals): Convert precision - amount.withAsset({ decimals, assetType }) - amount.percent(5): Calculate 5% - amount.mod(n), amount.abs(), amount.neg() - isAmount(value): Type guard - toAmount(value, decimals, symbol): Safe conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #63, Closes #64
变更
集成 Big.js 进行精确的十进制计算,并添加多项新功能。
Big.js 集成
序列化支持
格式化显示
精度转换
新增方法
toJSON()/fromJSON()- 序列化toDisplayString()- 带千分位的显示toDecimals()- 精度转换withAsset()- 从资产信息创建percent()- 百分比计算mod(),abs(),neg()- 更多运算isAmount()- 类型守卫toAmount()- 安全转换测试
63 个测试用例全部通过。