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

add modified rounding function used in M-2000C to Module #381

Merged
merged 5 commits into from
Oct 9, 2023
Merged

add modified rounding function used in M-2000C to Module #381

merged 5 commits into from
Oct 9, 2023

Conversation

jdahlblom
Copy link
Contributor

No description provided.

--- @param decimal_places integer
--- @return number
function Module.round2(num, decimal_places)
return tonumber(string.format("%." .. (decimal_places or 0) .. "f", num)) or 0
Copy link
Member

Choose a reason for hiding this comment

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

I haven't looked into it, but there must be a more efficient way to round than converting a value to a string and then back to a number again?

I suspect this is also a losing battle since some floats (like 0.3) basically can't be rounded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Googling the subject it seems that lua has weak support for rounding. This was suggested as the common way to do it on Stackoverflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

It's common, but not necessarily performant. At any rate, I suspect that my PR #392 should solve the problem at hand (and it's in the core set value code so it will apply to all controls).

@jdahlblom jdahlblom marked this pull request as ready for review October 9, 2023 15:18
@jdahlblom jdahlblom added this pull request to the merge queue Oct 9, 2023
Merged via the queue into DCS-Skunkworks:master with commit fd87614 Oct 9, 2023
@jdahlblom jdahlblom deleted the add-m2000-round branch October 9, 2023 15:37
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.

2 participants