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

Print leading zeroes after decimal point #1265

Merged
merged 1 commit into from Jul 12, 2023

Conversation

NotherNgineer
Copy link
Contributor

@NotherNgineer NotherNgineer commented Jul 12, 2023

Fixed the unit_auto_scale() function to enable padding with leading 0's after a decimal point.

For example, when displaying the value 1.025, previously it would appear as "1. 25" (with a space). Now it will correctly display as "1.025".

@NotherNgineer NotherNgineer marked this pull request as ready for review July 12, 2023 17:03
@gullradriel
Copy link
Member

Nice 👌 thanks: :-)

Copy link
Member

@gullradriel gullradriel left a comment

Choose a reason for hiding this comment

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

Let's see if it's going well after that one 👍

@NotherNgineer NotherNgineer merged commit fa4623d into portapack-mayhem:next Jul 12, 2023
3 checks passed
@NotherNgineer NotherNgineer deleted the leading-zeroes branch July 12, 2023 22:26
@kallanreed
Copy link
Contributor

Somewhat related: I want a to_string for MHz frequency that doesn’t do padding and other layout things. I just want to give it a frequency and and optional precision and get a properly rounded result back. So like 12345000, precision 0 is “12” precision 1 is “12.3” precision 2 is “12.35”, etc.

@NotherNgineer
Copy link
Contributor Author

Somewhat related: I want a to_string for MHz frequency that doesn’t do padding and other layout things. I just want to give it a frequency and and optional precision and get a properly rounded result back. So like 12345000, precision 0 is “12” precision 1 is “12.3” precision 2 is “12.35”, etc.

I'll be glad to create one, but busy all day today so it might be tomorrow. Is it just the number of digits to the right of the decimal that you're wanting to specify? (I thought perhaps you were trying to fit a value in a certain length field on the screen in which case the number of digits to the left of the decimal point might dictate the number of digits that will fit on the right) Secondly, note that '0' "padding" after the decimal point will still be desirable as this PR illustrates; e.g. frequency of 12045000 with precision 2 you'd want to be displayed as "12.05", not "12. 5".

@kallanreed
Copy link
Contributor

It's a little bit of a hack, but we could just insert a decimal point into a string. Might be simpler over all.
I guess the trick would be knowing where in the string to put the decimal, but that seems doable.
https://en.cppreference.com/w/cpp/string/basic_string/insert

I guess it could be just to_string the whole value so you have full precision then count from the right for every division by 10. End up with a weird special case for when the value is smaller that what you're dividing by where you have to add leading zeros. 🤔

@NotherNgineer
Copy link
Contributor Author

Please see if the new function I added in PR #1271 does what you're looking for.

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.

None yet

3 participants