Forum: Mikrocontroller und Digitale Elektronik Converting Float to Byte (123.456789 -> 123) need help from MikroBasic experts


von ERTA (Gast)


Lesenswert?

Hey Guys

Having a problem to convert a Float to a byte. Used language is 
Mikrobasic Pro 2010.

Having this code:

Dim DataFloat as Float
Dim DataByte as Byte

DataFloat = 40.000
DataFloat = DataFloat * 6.375   // Scale 40 to 8bit
DataByte = DataFloat


Now Databyte should be 255. But it isn't.
How can I get the number befor the point?
DataFloat is generated from a calculation and can not be normal integer, 
or so.

von Achim M. (minifloat)


Lesenswert?

Hey Dude,

I wonder if there aren't any conversion functions like Cint()
as known to me from Visual Basic(used that some years ago).

Maybe you have to include a library or so, as i don't know MikroBasic.

A second chance would be accessing the float as a int, manually 
splitting it in mantissa and exponent and convert that in a homebrewn 
function. :D

minifloat

von Achim M. (minifloat)


Lesenswert?

Maybe this will help you:
www.mikroe.com/eng/downloads/get/37/Fmikrobasic_pic_pro_manual_v101.pdf
Explicit conversions are explained at page 174.

regards,
minifloat

von ERTA (Gast)


Lesenswert?

The error was in the compiler. Updated it from 3.2 to 3.8 and all work 
wonderfull. But be aware before aupdating: You have to program all USB 
HID functions new !!!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.