scottvaughan Posted March 10, 2009 Posted March 10, 2009 I have a calculation where the result is 1.5. I need the value in my field to only be .5. How do I truncate or format the field so it only recognized the decimal point value.
LaRetta Posted March 11, 2009 Posted March 11, 2009 BTW, I began thinking further ... Mod ( numField ; 1 ) will not work for minus numbers. I believe it will work if there aren't any but I wanted it to be considered in your decision.
comment Posted March 11, 2009 Posted March 11, 2009 If number can be negative, you could use either: Mod ( Abs ( number ) ; 1 ) or: Mod ( number ; Sign ( number ) ) depending on whether you want the result to inherit the sign of the input or not.
LaRetta Posted March 11, 2009 Posted March 11, 2009 (edited) Ah. Sign(). I like that the best because it doesn't suppose ... it simply truncates and leaves the value as before (but only the remaining) portion. I also wanted to ask if it should be rounded but I assumed that was overkill ... UPDATE: Yes! This is best because it works both ways! Edited March 11, 2009 by Guest
Chappy.Cole Posted March 11, 2009 Posted March 11, 2009 There's one pitfall with the 'Mod ( number, Sign ( number ) )' method: Sign can return 0, which, if it does, Mod would be attempting to divide by 0, which is undefined. Of course this is a special case; however, this is precisely what we must always be worried about, i.e. the special cases! Well, excuse me. I just tried using the Mod & Sign calculation and it correctly calculated the value that scottvaughan wanted, e.g. number = 27.385 ==> calc. = .385 number = -17.129 ==> calc. = -.129 number = 0 ==> calc. = 0 That concerns me because FileMaker is making a non-standard choice for a mathematical function. If one created a calculation that resulted in dividing by zero, most software would display some special value like, "#undefined#" or the software would crash. Why would we want FileMaker to do something different? Sheeesh. I just did some more testing and FileMaker gives a completely incorrect answer when mixing positive and negative: Mod ( -17.129, 1) ==> .871 Sounds like a bug to me.
comment Posted March 11, 2009 Posted March 11, 2009 It's not a bug at all, but an intentional (and entirely commendable, IMHO) choice: http://filemaker.custhelp.com/cgi-bin/filemaker.cfg/php/enduser/std_adp.php?p_faqid=721 Too bad the description of the function in the help remains outdated: http://fmforums.com/forum/showpost.php?post/292075/
Recommended Posts
This topic is 5795 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now