Normal Topic Discard value if fractional? (Read 1040 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Discard value if fractional?
Mar 18th, 2008 at 1:55pm
Print Post Print Post  
I have several number elements that are formatted to display as whole numbers.  When a user enters a fraction he gets the message "Cannot...converting..." and the display converts to a whole number.  However, the fractional amount is retained within the element and then, if it's used elsewhere, hilarity ensues.

None of these elements need to be programmed to be rounded, but I would like to program them so a fractional amount cannot be retained.  That is, if a user enters a fractional amount the form rejects the entry entirely, clears it right out.  I'll create an alert so that he knows this has happened.  I may or may not use Throwfocus to toss him back into the element to try again, probably not because who needs that stress?.

What's the best way to check for a fraction?  I presume it would have something to do with examining for any non-zero digit following the decimal point, but I'm not sure how that would be done.

As always, thanks for any advice.
  

**
Captain Infinity
Back to top
IP Logged
 
MP
Full Member
***
Offline



Posts: 104
Joined: Sep 3rd, 2007
Re: Discard value if fractional?
Reply #1 - Mar 18th, 2008 at 2:53pm
Print Post Print Post  
Did you play with @Frac()?  I suspect this is all you need.

Code
Select All
If @Frac( @TONUMBER( txtLayoutElement )) > 0 Then {
...
} 

  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Discard value if fractional?
Reply #2 - Mar 18th, 2008 at 3:44pm
Print Post Print Post  
Even simpler:
Code
Select All
var aa as int

aa = field_name
field_name = aa
 



By forcing the field value (by default a floating point number) through an integer, you remove any fractional portion.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Discard value if fractional?
Reply #3 - Mar 18th, 2008 at 4:54pm
Print Post Print Post  
Thanks guys, I tried both of these and both worked.  However, before any programming runs Sesame insists on telling the user that it is converting the value, and then it rounds it (in the display only!), so what I wound up doing was programming the elements so the retained value actually rounds.  Not quite what I was hoping for but it will do.  Thanks again.
  

**
Captain Infinity
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Discard value if fractional?
Reply #4 - Mar 18th, 2008 at 5:34pm
Print Post Print Post  
Infinity wrote on Mar 18th, 2008 at 4:54pm:
However, before any programming runs Sesame insists on telling the user that it is converting the value, and then it rounds it (in the display only!)


Remove the custom output format and it will stop nagging you.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Discard value if fractional?
Reply #5 - Mar 19th, 2008 at 1:48am
Print Post Print Post  
Quote:
Even simpler:
Code
Select All
var aa as int

aa = field_name
field_name = aa
 



By forcing the field value (by default a floating point number) through an integer, you remove any fractional portion.


Just curious, isn't that the same as the code below? Is there something I'm overlooking?
Code
Select All
field_name = @Int(field_name) 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Discard value if fractional?
Reply #6 - Mar 19th, 2008 at 1:52am
Print Post Print Post  
Quote:
Just curious, isn't that the same as the code below? Is there something I'm overlooking?
Code
Select All
field_name = @Int(field_name) 



Very similar. Your way has the benefit of clarity.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Discard value if fractional?
Reply #7 - Mar 19th, 2008 at 2:40pm
Print Post Print Post  
Thanks Mark. Smiley

I thought maybe there was some additional stuff going on 'under the hood' that only you knew about. Wink
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged