1

I'm working on creating a workbench for testing the performance of sorting algorithms. For some of my performance stats, it appears that the results aren't being returned correctly. Larger values are being stored as decimals with an E towards the end for example 1.2497388E7 instead of an 8 digit whole number. I'm just wondering if anyone knows what might be causing this.

Results from Running sorting algorithm for various sizes of arrays

Thanks

kleopatra
  • 51,061
  • 28
  • 99
  • 211
John
  • 9
  • 1
  • If you are using a double, this is the standard output. Do you want a floating point number or instead a whole number? – J Fabian Meier Apr 02 '20 at 09:59
  • You can create a BigDecimal and use toSimpleString if you would like to avoid the exponential notation. You also might consider outputing your smaller floats with exponential notation as it can be convenient for comparing. – matt Apr 02 '20 at 10:09
  • Related: [How do I print a double value without scientific notation using Java?](https://stackoverflow.com/questions/16098046/how-do-i-print-a-double-value-without-scientific-notation-using-java) – Mark Rotteveel Apr 11 '20 at 10:35

2 Answers2

1

This is common mathematical notation to show that the number is what is displayed x10^ what's after E :)

For example:

1.24E5 = 124000 (1.24*10^5).

In other words: It's just a really big number

CoderMuffin
  • 519
  • 1
  • 10
  • 21
0

I don't think that this is a problem with the data itself (that should be stored correctly); it's probably more to do with how you are outputting it.

When your number is over a certain threshold of size, it is common to notate it in a compressed fashion using E. This is used to denote standard form, which is where a number is written in the form number x 10^n.

If you are using the standard System.out functions for the console, it is probably being formatted that way automatically due to size.

If you want to prevent this, use System.out.printf with the %f flag for formatting.

For example:

double number = 10.5;
System.out.printf("Value at double is: %f\n", number);

For more info, see the format documentation

EMarshall
  • 125
  • 8