D
D
Dmax992020-11-25 22:28:24
Java
Dmax99, 2020-11-25 22:28:24

How to divide by tenths if they hit?

Hello, please tell me how to multiply and divide if the number comes across with tenths?

String res = String.valueOf(input1 * porci2 / 100);

and if a number with tenths or hundredths comes across in porci2, then the application crashes ...
Please tell me how to fix it ??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2020-11-26
Hasanly @azerphoenix

Hello!
I recommend that you seriously study the basics of programming and, in particular, programming in Java. Understand concepts such as dynamic and static typing.
Java is a statically typed language. This means that the type of a variable is declared at the time it is declared. I also recommend reading about such concepts. as explicit and implicit type casting.
Based on the above, the following is not clear:

and if a number with tenths or hundredths comes across in porci2, then the application crashes ...

Where does the number with tenths and hundredths come from in the porci2 or input1 variable?
I suspect that the porci2 and input1 values ​​are some kind of int or long value, and from the outside you are assigning a real number type to these variables. If so, use the type double for these variables and that should solve the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question