It’s because you’re doing integer division.
Divide by a double or a float, and it will work:
double scale = ( n / 1024.0 ) * 255 ;
Or, if you want it as a float,
float scale = ( n / 1024.0f ) * 255 ;
More Related Contents:
- Why does integer division code give the wrong answer? [duplicate]
- Division between integers in Java
- Integer division in Java [duplicate]
- Fast algorithm to calculate n! / (q!)^r
- How to make fibonacci method? [closed]
- is there an algorithm to reverse a chosen part of a number? [closed]
- Division of integers in Java [duplicate]
- Integer division: How do you produce a double?
- How to convert number to words in java
- How to resolve a Java Rounding Double issue [duplicate]
- How to parse a mathematical expression given as a string and return a number? [duplicate]
- Strange floating-point behaviour in a Java program [duplicate]
- Fastest way to determine if an integer’s square root is an integer
- Method for evaluating math expressions in Java
- Mod in Java produces negative numbers [duplicate]
- How does java do modulus calculations with negative numbers?
- How to handle very large numbers in Java without using java.math.BigInteger
- Is it possible to pass arithmetic operators to a method in java?
- MathML and Java [closed]
- How can I check if multiplying two numbers in Java will cause an overflow?
- midpoint between two latitude and longitude
- Is there a commonly used rational numbers library in Java?
- Calculating the angle between two lines without having to calculate the slope? (Java)
- Nice Label Algorithm for Charts with minimum ticks
- What to do with Java BigDecimal performance?
- Algorithm to generate Poisson and binomial random numbers?
- ArithmeticException thrown during BigDecimal.divide
- What is a non recursive solution for Fibonacci-like sequence in Java?
- How to rotate a vertex around a certain point?
- How to round up integer division and have int result in Java? [duplicate]