Jump to content

Recommended Posts

Dear all,

I am going to use the float.h and float.pic18.lib files.

Since I am going to calculate floats and I need to represent them on a LCD display, I have only one idea to work-around the missing "%f" in the lprintf format; I multiplicate the float variable by 10 (for example, needing only one decimal digit), convert it into long variable and then calculate the integer part (with sign) and the decimal of that long variable.

 

That should give me more possibilities to show a float-to-long variable on LCD...

 

Any other ideas?

 

Thank you.

 

Paolo.

Share this post


Link to post
Share on other sites

This basically does what you suggested.

 

Just format the intPart and fracPart with a decimal point between into a string.

 

void main(void) {
float	myfloat;
int32	intPart;
int32	fracPart;

myfloat = 3.14;

intPart = float32_to_int32(myfloat);
fracPart = float32_to_int32(float32_mul(float32_sub(myfloat, float32_from_int32(intPart)), 10.0));
}

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...