Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:06 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBasic and string handling with non-integers

Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 06:28am 19 Dec 2020
Copy link to clipboard 
Print this post

Is this the expected behaviour?

> a$ = "123456789"
> print left$(a$,1.4)
1
> print left$(a$,1.5)
12

What is happening, you ask?
The number part of the left$ function is being ROUNDED, not truncated.

This is with a CMM2, although I presume other MMBasic devices do the same.

Comments?
Visit Vegipete's *Mite Library for cool programs.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 06:47am 19 Dec 2020
Copy link to clipboard 
Print this post

That is what happens when you get a float to integer conversion.
If you prefer to truncate, use INT or FIX

dim integer x
dim float y

for y = 0 to 2 step 0.1
x = y
print x,y
next y


Jim
VK7JH
MMedit
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 07:05am 19 Dec 2020
Copy link to clipboard 
Print this post

Okey-dokey. FIX it is.
Visit Vegipete's *Mite Library for cool programs.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025