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

added formatting helpers for balance (zcn,mzcn,uzcn,sas) #10 #225

Merged
merged 3 commits into from
Sep 8, 2021

Conversation

bbist
Copy link
Contributor

@bbist bbist commented Sep 1, 2021

This PR includes formatting helpers used to format balance (ZCN) to string for CLI applications. It addresses the issue raised here: 0chain/zwalletcli#10

case MZCN:
return fmt.Sprintf("%.3f mZCN", float64(token)/1e6)
}
return fmt.Sprintf("%.3f ZCN", float64(token)/1e9)
Copy link
Contributor

Choose a reason for hiding this comment

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

According to this issue here

0.0000000001 ZCN = 0.0000001 mZCN = 0.0001 µZCN = 1 sas 

reverse of this

1 µZCN = 1e4 sas
1 mZCN = 1e7 sas
1 ZCN = 1e10 sas

But i see you have considered only 1e9

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed the testFormat() function is wrong. I think the confusion lies is Saswatas not being a 3rd power of decimals like usual thousand separators. It should use 1e4, 1e7 and 1e10. Saswatas shouldn't really be displayed if we set threshold for displaying uzcn to 4 decimals, e.g. 1 sas = 0.0001 µZCN

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, the format chosen by autoformat is a separate layer to the amount of raw zcn being shown.

That is, there could be user preference to show amounts as zcn down to 0.01 ZCN, then below that e.g. 0.0099 would be shown as 9.9mZCN.

Copy link
Contributor Author

@bbist bbist Sep 3, 2021

Choose a reason for hiding this comment

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

@NoSkillGuy, @sculptex thanks for pointing it out. I"ll fix the order as 1 zcn = 1e10 sas.

@bbist
Copy link
Contributor Author

bbist commented Sep 3, 2021

We could also do with a slightly different way to show these smaller denominations so they are more clearly distinct from ZCN in GUI environments.

I thought a different font colour and/or progressively smaller font size for smaller denominations might help. Could these formats be in some sort of helper function.

E.g. these are based on output denomination

getCol(zcn) returns default
getCol(mzcn) returns orange
getCol(uzcn) returns color blue
etc.

getSize (zcn) returns 1 (100%)
getSize (mzcn) returns 0.9 (90%)
getSize(uzcn) returns 0.8 (80%)
etc.

@sculptex, I guess I could add additional functions to format them into html as well as for CLI with color support. For a client side UI code, it makes sense to implement the same logic separately.

Copy link
Contributor

@sculptex sculptex left a comment

Choose a reason for hiding this comment

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

Looks numerically correct now for values but only on mobile so can't check fully.

Since sas are lowest denomination, it doesn't make sense to have decimal places on those?
There is also scope on ZCN if value is large, e.g. 1,000,000ZCN you really aren't bothered with showing 3 decimal places. There could either be a straight cut off above a certain value, or decrease decimal places,
e.g.
<1,000 3 decimals

=1,000 2 decimals
=10,000 1 decimal
=100,000 no decimals

@bbist
Copy link
Contributor Author

bbist commented Sep 8, 2021

Looks numerically correct now for values but only on mobile so can't check fully.

Since sas are lowest denomination, it doesn't make sense to have decimal places on those?
There is also scope on ZCN if value is large, e.g. 1,000,000ZCN you really aren't bothered with showing 3 decimal places. There could either be a straight cut off above a certain value, or decrease decimal places,
e.g.
<1,000 3 decimals

=1,000 2 decimals
=10,000 1 decimal
=100,000 no decimals

Removed decimal formatting from SAS, but left the 3 digit formatting on ZCN (unit) for now. I'll merge this PR and tag with a new version so that we can update the dependency on zwalletcli and zboxcli.

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.

3 participants