How to get most significant digit ?
-
Hi ! I need to retrieve the most significant digit of a number. This must also be rounded to the inferior 'unit'. Example: I have 5238.12 and I must have 1000.00 I have 0.02578 and I must have 0.01000 I have 5.45 and I must have 1.00 Any idea ? Thanks
-
Hi ! I need to retrieve the most significant digit of a number. This must also be rounded to the inferior 'unit'. Example: I have 5238.12 and I must have 1000.00 I have 0.02578 and I must have 0.01000 I have 5.45 and I must have 1.00 Any idea ? Thanks
Ok I've found a solution: I can calculate the log10 of the number. I round the solution to integer value. This integer value will give me the number of zero of the number for 5238.12 the log10 is 3.7192. So I know I have 3 zeros... :-D Negative numbers will give me the floating point position.
-
Hi ! I need to retrieve the most significant digit of a number. This must also be rounded to the inferior 'unit'. Example: I have 5238.12 and I must have 1000.00 I have 0.02578 and I must have 0.01000 I have 5.45 and I must have 1.00 Any idea ? Thanks
Try this code: d=pow(10,(int)floor(log10(f))); f=input, d=output.
-
Ok I've found a solution: I can calculate the log10 of the number. I round the solution to integer value. This integer value will give me the number of zero of the number for 5238.12 the log10 is 3.7192. So I know I have 3 zeros... :-D Negative numbers will give me the floating point position.
Cool!!!
MSN Messenger. prakashnadar@msn.com Tip of the day of visual C++ IDE. "We use it before you do! Visual C++ was developed using Visual C++"
-
Try this code: d=pow(10,(int)floor(log10(f))); f=input, d=output.
Great :-) ! I found the same solution as you at the same time :-D (but your explanation is simpler that mine ;P ) Thanks