Math.ceil()
is the correct function to call. I’m guessing a
is an int
, which would make a / 100
perform integer arithmetic. Try Math.ceil(a / 100.0)
instead.
int a = 142; System.out.println(a / 100); System.out.println(Math.ceil(a / 100)); System.out.println(a / 100.0); System.out.println(Math.ceil(a / 100.0)); System.out.println((int) Math.ceil(a / 100.0));
Outputs:
1 1.0 1.42 2.0 2
Related Posts:
- Integer division in Java [duplicate]
- How to round a number to significant figures in Python
- How to save decimal in java
- Round *UP* to the nearest 100 in SQL Server
- How do I convert a String to an int in Java?
- Converting bytes to megabytes
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- Java – Convert integer to string [duplicate]
- Converting 3D polar coordinates to cartesian coordinates
- What is the C++ function to raise a number to a power?
- Unfamiliar symbol in algorithm: what does ∀ mean? [closed]
- How to round a number to n decimal places in Java
- How can I use “e” (Euler’s number) and power operation in python 2.7
- Python division
- How can I convert a char to int in Java? [duplicate]
- What does the ^ (XOR) operator do? [duplicate]
- Safest way to convert float to integer in python?
- How can I use “e” (Euler’s number) and power operation in python 2.7
- Convert int to char in java
- “int cannot be dereferenced” in Java
- Calculating a 2D Vector’s Cross Product
- Converting double to integer in Java
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Java JDK – possible lossy conversion from double to int
- Round a double to 2 decimal places [duplicate]
- Round a double to 2 decimal places [duplicate]
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Round a double to 2 decimal places
- JavaScript exponents
- How to round up to the next integer?
- What does != do/mean in python
- How do I limit the number of decimals printed for a double?
- How to perform an integer division, and separately get the remainder, in JavaScript?
- How do I limit the number of decimals printed for a double?
- How to perform an integer division, and separately get the remainder, in JavaScript?
- Clamping floating numbers in Python?
- How to check if an int is a null
- Lua replacement for the % operator
- How do you find the rightmost digit of an integer?
- What is the fastest factorial function in JavaScript?
- How to check whether a int is not null or empty?
- What is the best math library to use with java?
- What is the best math library to use with java?
- Always Round UP a Double
- What is the difference between Integer and int in Java?
- How to round up the result of integer division?
- How to perform bilinear interpolation in Python
- What is the most efficient way to calculate the least common multiple of two integers?
- What is the most efficient way to calculate the least common multiple of two integers?
- Using Math.round to round to one decimal place?
- How can I convert a number from base 8 to base 10?
- Inverse of Tan in python (tan-1)
- Inverse Cosine in Python
- What is the maximum number of edges in a directed graph with n nodes?
- Probability of hash collision
- Java, Simplified check if int array contains int
- JAVA Variable declaration not allowed here
- Java Array Sort descending?
- Inverse Logistic Function / Reverse Sigmoid Function
- Division of integers in Java
- Determine if a String is an Integer in Java [duplicate]
- Best way to represent a fraction in Java?
- Convert boolean to int in Java
- Convert double to Int, rounded down
- How to Convert Int to Unsigned Byte and Back
- Java – Change int to ascii
- Calculate Average Java
- Rotating a Vector in 3D Space
- Mathematica matrix diagonalization
- What are the -Xms and -Xmx parameters when starting JVM?
- How to match “any character” in regular expression?
- Exception in thread “main” java.lang.Error: Unresolved compilation problems
- Error java.lang.OutOfMemoryError: GC overhead limit exceeded
- How to create a sub array from another array in Java?
- How do order of operations go on Python?
- “Missing return statement” within if / for / while
- A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1
- Java Method Stubs
- How to install Java 8 on Mac
- unused import statement for used ones in IntelliJ IDEA
- Unsigned long in Java
- Integer range when using 64bit jdk
- Removing whitespace from strings in Java
- what is this ANT build?
- org.apache.jasper.JasperException: Unable to compile class for JSP:
- Drawing Hexagon Using Java error
- How do I parse command line arguments in Java?
- Missing method body, or declare abstract in Java
- java code is showing error. ( ‘;’,expected)
- Efficient swapping of elements of an array in Java
- Jackson with JSON: Unrecognized field, not marked as ignorable
- Create a two dimensional string array anArray[2][2]
- How to calculate an angle from three points?
- Java: Not a statement
- how to use drawArc()
- How to add RGB values into setColor() in Java?
- Can you write virtual functions / methods in Java?
- Creating video player using Java
- Can I override and overload static methods in Java?
- How can i fix this equals on primitive type(int)