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

Implement Dec() and PrettyDec() properly #129

Closed
karalabe opened this issue Mar 21, 2023 · 5 comments
Closed

Implement Dec() and PrettyDec() properly #129

karalabe opened this issue Mar 21, 2023 · 5 comments

Comments

@karalabe
Copy link
Contributor

When printing ints in logs or console, it's usually better to print as a decimal vs hex. But there's no way to flatten a uint256 Int currently into a decimal string. It feels a bit wonky to do uint256.Int.ToBig().String()

@holiman
Copy link
Owner

holiman commented Mar 21, 2023

There should be two methods:

  • One that prints to decimal: e.g 123012313 (see Dec below)
  • One that pretty-prints with thousands-separators: 123,012,313 (PrettyDec?)

ps, Dec exists and currently looks like this:

func (z *Int) Dec() string {
	return z.ToBig().String()
}

@karalabe
Copy link
Contributor Author

Erm, it does not exist?

@karalabe
Copy link
Contributor Author

Ah, sry, when I backported the log change from my PR I didn't backport bumping the uint256 lib version.

@holiman
Copy link
Owner

holiman commented Mar 21, 2023

I'll reopen this, we should still implement it "properly" without going via big

@holiman holiman reopened this Mar 21, 2023
@holiman holiman changed the title ToDecimal or similar? Implement Dec() and PrettyDec() properly Mar 21, 2023
@holiman
Copy link
Owner

holiman commented Mar 22, 2023

Fixed by #130

@holiman holiman closed this as completed Mar 22, 2023
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

No branches or pull requests

2 participants