简体   繁体   中英

finding the smallest floating point numbers in java

I really don't understand then,] as I not too good with maths. I've searched around but I can't really find anything to help me.

what I need to know is which one of these floating point numbers is the smallest

a. 28.268E-5f
b. 0.0000002763E4f
c. 282479.9E-9f
d. 0.2764E-2f

I'm not asking for the answer, if you don't want to give it to me, but more of a way for me to figure it out myself. In simple terms.

This is basic maths, not specific to Java. The "E(some number)" bit is short for "10 to the power of (some number)".

So 1E-5 is 1 x 10^-5 which is 0.00001 (1 divided by 10 5 times).

2E-5 would be 0.00002 and so on. Hopefully that gives you enough to figure out how to expand the numbers you have and see which is smallest.

The answer is c) 282479.9E-9f

For your clarity E stands for exponent that is 10 power the digit following it. so 1.0E-2 = 0.01

28.268E-5f     = 0.00028268 
0.0000002763E4 = 0.002763 
282479.9E-9    = 0.0002824799
0.2764E-2      = 0.0027464

probably the safest bet is to create a float[] containing your values, and use an array sorting algorithm to order them smallest to largest, from there-on-in, you can find the smallest, largest, medium values. Check this out. http://www.java-examples.com/java-sort-float-array-example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM