my objective is to multiply any 2 numbers(int). The numbers can be extremely large (i.e. run into hundreds of digits) and are provided as strings. The expected output is a string which represents the product of the two numbers. "output shuld be a integer." here is what i coded.
public class LargeMultiply { static String test1a = "268435456"; static String test1b = "524288"; static String testcaseA = test1a; static String testcaseB = test1b; public static void main(String args[]){ LargeMultiply inst = new LargeMultiply(); String v = inst.multiply(testcaseA,testcaseB); System.out.println(v); } public String multiply(String num1, String num2){ Long a=Long.parseLong(num1); Long b=Long.parseLong(num2); return String.valueOf(a*b); } }
and here are outputs
if inputs are 268435456 524288 these then output is 140737488355328 the above code perform well in this case.
if inputs are 26843545623423 52428824234 then expected output is 1407375535307804420432982 this but it gives a -ve value due to max limit reached for "long" but if i use "double' then answer is in scientfic form and that is not needed i want output in integer form.
Is any way to display double in normal form(not with decimal point)??