Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:05 06 Jul 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 : leading zero

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:00pm 24 May 2016
Copy link to clipboard 
Print this post

IF I want to say send measurements from a direction sensor in degrees
HOW can I code it so there is always 3 digits?
ie 9 degrees and under reads 009
10 and over reads 010
and 100 and over reads 100
I need it so it's always sending 3 digits with 0's under 99
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10213
Posted: 11:16pm 24 May 2016
Copy link to clipboard 
Print this post

right$(str$(direction+1000),3)
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:20pm 24 May 2016
Copy link to clipboard 
Print this post

Manual page 78.

[code]
STR$(Direction, 3, 0, "0")
[/code]

test some numbers:
[code]
STR$(9, 3, 0, "0")
STR$(10, 3, 0, "0")
STR$(100, 3, 0, "0")
[/code]Edited by MicroBlocks 2016-05-26
Microblocks. Build with logic.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:23pm 24 May 2016
Copy link to clipboard 
Print this post

Thanks everyone
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 07:40am 27 Jun 2016
Copy link to clipboard 
Print this post

I've been reading the manual about this and I'm totally confused
I understand that if I want to print a number it can be a certain number of digits before or after the decimal point

but what do you do when you want to print the value of a "label"?

for instance in the wind speed program I'm trying to sort out

wSpeed=(windfactor*reading)/(testpause/1000)

I can do this

PRINT wSpeed "" and it will print the speed, but how can I tell it that I only want it to 2 decimal places?

OR how can I limit wSpeed to 2 decimal places?
Edited by lew247 2016-06-28
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10213
Posted: 08:03am 27 Jun 2016
Copy link to clipboard 
Print this post

Same as above - use STR$

print STR$(wSpeed,3,2)

If you wanted to actually adjust the number you could use

wSpeed= CINT(wSpeed*100)/100.0
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:25am 27 Jun 2016
Copy link to clipboard 
Print this post

Thanks
Got it working with everything apart from bme280_read_humidity but I can live with that Edited by lew247 2016-06-28
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:01am 27 Jun 2016
Copy link to clipboard 
Print this post

Thanks Peter, works great



 
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