1

I want to show factorial of a number in scientific notation.

For example - 100! = "9.332621544e+157"

Is there any other way to do this besides NumberFormat? This is my code so far -

BigDecimal res=new BigDecimal("1");
for(int i=2;i<=x;i++){
   res=res.multiply(BigDecimal.valueOf(i));
}
str=String.valueOf(res+"");
display.setText(str);

I'm really sorry if this question is vague to understand. Any help would be appreciated. Thanks in advance.

JavaHopper
  • 5,567
  • 1
  • 19
  • 27
MI Sabic
  • 367
  • 2
  • 7
  • 18

2 Answers2

1

Not nice but changing

str=String.valueOf(res+""); 

to

String str=res.doubleValue()+""; 

will do the job

Eritrean
  • 15,851
  • 3
  • 22
  • 28
0

Using NumberFormat is the way to go but if you don't want to use that you could use a PrintStream

See Formatting Numeric Print Output for more info

Jayfray
  • 415
  • 3
  • 12