-5

Please tell me how to divide the numbers by the column, but taking into account the fact that the numbers in the method will be transferred by the type String (the number to be divided, the number to which to divide). Because numbers can simply be very huge decimals. The output from the class must be in String format. (public String devide (String toDevide, String whichDevide)) - starts with that

AC_NONE
  • 5
  • 2
  • 4
    [`BigDecimal`](https://docs.oracle.com/javase/10/docs/api/java/math/BigDecimal.html) or [`BigInteger`](https://docs.oracle.com/javase/10/docs/api/java/math/BigInteger.html) maybe? – Seelenvirtuose Feb 11 '19 at 08:30
  • If `BigInteger` is for some reason not applicable, still you can check: https://stackoverflow.com/questions/48582606/divide-two-large-numbers-as-strings-without-using-bignumbers-in-java – vahdet Feb 11 '19 at 08:31
  • please be precise with your question. Give a example – Durgesh Kumar Feb 11 '19 at 08:31
  • Welcome to Stack Overflow. While I disagree that your question is unclear, it is certainly (1) poorly researched (2) too broad for Stack Overflow. Always search and research before asking, please. An effort on your part will almost always be matched by one on ours. – Ole V.V. Feb 11 '19 at 09:10
  • Possible duplicate of [How Do I convert very big String to number in Java](https://stackoverflow.com/questions/12967201/how-do-i-convert-very-big-string-to-number-in-java) – Ole V.V. Feb 11 '19 at 09:15

1 Answers1

3

Use BigInteger or BigDecimal class and make use of their divide() method.

Lino
  • 19,604
  • 6
  • 47
  • 65
Norbert Bicsi
  • 1,562
  • 2
  • 19
  • 33
  • I tried. But when i execute it that happends: Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.base/java.math.BigDecimal.divide(BigDecimal.java:1722) at informatika.Main.D(Main.java:90) at informatika.Main.run(Main.java:46) at informatika.Informatika.main(Informatika.java:19) \nbproject\build-impl.xml:1328: The following error occurred while executing this line: \nbproject\build-impl.xml:948: Java returned: 1 – AC_NONE Feb 11 '19 at 11:42
  • cos i divide (1/19) and i need to get 100 number after point – AC_NONE Feb 11 '19 at 11:42
  • @ОоррЛллл Sounds like https://stackoverflow.com/questions/4591206/arithmeticexception-non-terminating-decimal-expansion-no-exact-representable – Norbert Bicsi Feb 11 '19 at 12:02