If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Formula to return the decimal of a Value

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-22-10, 18:02
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
Formula to return the decimal of a Value

Is there another formula that will return just the fraction value of a decimal number. I came up with this:

=A1-INT(A1)

If A1 has 5.3 this would return .3
I've seen another way of doing this but don't remember what it is.
__________________
~

Bill
Reply With Quote
  #2 (permalink)  
Old 02-23-10, 02:56
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 477
Hi,

Your formula won't produce the correct result if A1 contains a negative number.

If negative numbers are not a concern then you can simplify it to:
Code:
=MOD(A1,1)
If negative numbers are a concern then you could use a variation such as:
Code:
=ABS(MOD(A1,SIGN(A1)))
Hope that helps...
__________________
Colin

My Excel articles

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #3 (permalink)  
Old 02-23-10, 21:25
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
Colin,

This works great in a formula.
=MOD(A1, 1)

In VB this does not work due to the rounding of values by the Mod Operator. I was looking for some options that would work well in VB.

val = Range(A1) Mod 1

The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result.

I'm pasting some values from a pivot table into another sheet and want to set the decimal to 1 place if it has a decimal or 0 decimals if it is a whole number. The original formula I posted is doing the trick. I was curious about optional ways of doing this.

Thanks for the suggestions.
__________________
~

Bill
Reply With Quote
  #4 (permalink)  
Old 02-24-10, 15:28
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 477
Hi Bill,

There are some differences between the VBA Mod operator and the Excel Mod worksheet function.

If you want to, you can indirectly call the Excel Mod worksheet function in VBA by evaluating the formula expression. For example:
Code:
Debug.Print CStr(Sheet1.Evaluate("=MOD(A1,1)")
Hope that helps...
__________________
Colin

My Excel articles

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
Reply

Tags
decimal, excel, formula, integer, remainder

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On