-
-
Notifications
You must be signed in to change notification settings - Fork 399
ExprDecimalPlaces #7953
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
base: dev/feature
Are you sure you want to change the base?
ExprDecimalPlaces #7953
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double.toString always contains a dot
src/main/java/ch/njol/skript/expressions/ExprDecimalPlaces.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you suggest? I was originally going to make it:
So default behavior would use the |
Well I think you should be using Skript.toString() to convert the number to a string, which will respect the number accuracy. |
So something like this? for (Number number : numbers.getArray(event)) {
if (!(number instanceof Double doubleValue))
continue;
long decimalPlace = 0L;
double x = Double.valueOf(doubleValue);
while (Math.abs(x % 1) > 1e-9) {
x /= 10;
decimalPlace++;
}
decimalPlaces.add(decimalPlace);
} |
yes but i should have said multiply not divide |
} | ||
double x = Double.valueOf(doubleValue); | ||
long decimalPlace = 0L; | ||
for (int i = 0; i < limit; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why have both i and decimalPlace?
also i don't think this limit thing would work very well. Take 1.00001
. With accuracy set to 2, this would print as 1
, but have 2 decimal places. I think you'll need to round the number to the limit first.
@@ -0,0 +1,19 @@ | |||
test "decimal places": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs tests for floating point error stuff like places of 0.3/0.1
Problem
There is no expression allowing users to get how many decimal places a number goes into. Also was requested in the linked issue.
Solution
Adds
ExprDecimalPlaces
allowing users to quickly and easily get how many decimal places a number goes into.Testing Completed
ExprDecimalPlaces.sk
Supporting Information
N/A
Completes: #7948
Related: none