It is currently Sat Apr 29, 2017 2:20 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: INT function
Unread postPosted: Fri Jan 20, 2017 4:47 pm 
Offline

Joined: Sat Nov 26, 2016 4:23 pm
Posts: 11
Hi,
Was expecting an integer result, eg. 97 without a decimal and decimal-zero :-

BikeIndex = Int(Val(form_field$[1]))

where form_field$[1] = "97"
the resulting numeric value was 97.0 :!:

What/user is wrong here?
Thanks,
chrisRoald


Top
 Profile  
 
 Post subject: Re: INT function
Unread postPosted: Fri Jan 20, 2017 5:06 pm 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 644
Location: UK
chrisRoald wrote:
Hi,
Was expecting an integer result, eg. 97 without a decimal and decimal-zero :-

BikeIndex = Int(Val(form_field$[1]))

where form_field$[1] = "97"
the resulting numeric value was 97.0 :!:

What/user is wrong here?
Thanks,
chrisRoald

You need to distinguish between the value and the representation. The INT() function will remove any fractional part from the value. But it delivers a number which is always floating point in Basic! So if you display/print it will have .0 unless you use a display formatting for an integer.

But note the special case in the manual:
Quote:
USING$() has a special relationship with the math functions that intrinsically produce integer results.

BASIC! converts the output of these functions to floating point, for storage in numeric variables, but USING$() can get the original integer values.


HTH, Mike.


Top
 Profile  
 
 Post subject: Re: INT function
Unread postPosted: Fri Jan 20, 2017 11:33 pm 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1317
To remove any fractional part from a value and print it, you could use 'int$()'

Code:
Rem int$

x = 22.456

?int$(x)



prints 22


Top
 Profile  
 
 Post subject: Re: INT function
Unread postPosted: Sat Jan 21, 2017 4:24 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 644
Location: UK
Either way, the problem was with the expectation, not a bug...

Mike.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: [email protected] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred