![]() |
How do I isolate the Fractional part of a number in Excel VB?
I'm a novice writing a VB program in Excel 2003, and I need to isolate the fractional part of a number. In other words... Input: 23.0891467 Output: 0.0891467 The only way I know of to do this is (Result = Input Mod 1). The problem, is that while the Mod Operator works as a Worksheet Function - when used as a VB Operator, Excel truncates the fractional portion of the result. This, of course, makes it useless to me. I need to know the best way to isolate the fractional portion of a number (with maximum precision), that will work in Excel VB. Any help will be appreciated! Thanks! :) |
How do I isolate the Fractional part of a number in Excel VB?
Dim Num as double
num = 23.0891467 num = num - int(num) Is one way. Cumulous wrote: I'm a novice writing a VB program in Excel 2003, and I need to isolate the fractional part of a number. In other words... Input: 23.0891467 Output: 0.0891467 The only way I know of to do this is (Result = Input Mod 1). The problem, is that while the Mod Operator works as a Worksheet Function - when used as a VB Operator, Excel truncates the fractional portion of the result. This, of course, makes it useless to me. I need to know the best way to isolate the fractional portion of a number (with maximum precision), that will work in Excel VB. Any help will be appreciated! Thanks! :) -- Dave Peterson |
How do I isolate the Fractional part of a number in Excel VB?
Dim input as double, output as double
Output=Input-int(Input) Sub GetFraction() Dim x As Double, y As Double x = 23.0891467 y = x - Int(x) Debug.Print y End Sub y=8.91467000000006E-02 "Cumulous" wrote: I'm a novice writing a VB program in Excel 2003, and I need to isolate the fractional part of a number. In other words... Input: 23.0891467 Output: 0.0891467 The only way I know of to do this is (Result = Input Mod 1). The problem, is that while the Mod Operator works as a Worksheet Function - when used as a VB Operator, Excel truncates the fractional portion of the result. This, of course, makes it useless to me. I need to know the best way to isolate the fractional portion of a number (with maximum precision), that will work in Excel VB. Any help will be appreciated! Thanks! :) |
All times are GMT +1. The time now is 03:34 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com