![]() |
Inputbox error? 10 divided by 100 equals 0.100000001490116 ???
Hey, guys. I was setting up an inputbox for percentile value input, and the weirdest thing happened. The code follows. ==================== Option Explicit Sub inputboxtest() Dim aa As Single aa = Application.InputBox(Prompt:="Type in 10 for 10 percent", Type:=1) / 100 MsgBox aa ActiveSheet.Range("a1").Value = aa End Sub ==================== Why is this happening? Msgbox shows 0.1 but the value in the cell A1 is not the same value. What am I missing? Thanks. -- staying ------------------------------------------------------------------------ staying's Profile: http://www.excelforum.com/member.php...o&userid=23230 View this thread: http://www.excelforum.com/showthread...hreadid=385805 |
Inputbox error? 10 divided by 100 equals 0.100000001490116 ???
Hi,
0.1 of Double and 0.1 of Single are not same and not just 0.1. See http://support.microsoft.com/default...kb;en-us;78113 Floating-point arithmetic may give inaccurate results in Excel (BTW, "0001100110011100110011 (and so on)" is wrong.) You should use Double type for cell values, like: Dim aa As Double -- HTH okaizawa staying wrote: Hey, guys. I was setting up an inputbox for percentile value input, and the weirdest thing happened. The code follows. ==================== Option Explicit Sub inputboxtest() Dim aa As Single aa = Application.InputBox(Prompt:="Type in 10 for 10 percent", Type:=1) / 100 MsgBox aa ActiveSheet.Range("a1").Value = aa End Sub ==================== |
All times are GMT +1. The time now is 03:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com