Go to Post Action x (Passion Vision) = Goal - EricH [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-02-2007, 03:50
Bomberofdoom's Avatar
Bomberofdoom Bomberofdoom is offline
Biggest FIRST addict in Israel
AKA: Nir Levanon
FRC #2230 (Zcharia's Angels)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Israel
Posts: 471
Bomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond reputeBomberofdoom has a reputation beyond repute
Send a message via MSN to Bomberofdoom
Printing floats.

Having troubles working with float varibles, we're trying to solve the problems, but $f doesn't print float varibles.
If not, then how?
  #2   Spotlight this post!  
Unread 18-02-2007, 11:15
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Printing floats.

Read the docs for the C compiler/C library. Floating point format is not supported in the C18 printf.

You can roll your own if you know the range of values (like between .01 and 99.99) by converting to a fixed point integer for example, or by just using fixed point arithmatic instead of float or double.


For example, we have PID factors that are 0.00 to 9.99 in range using fixed point; something like correction = (p * proportion)/100; and proportation is a signed int in the range of 0..999 which represents 0.00 to 9.99 as previously stated. I use the following to convert proportion to a friendly output value. I don't have to worry about sign since it is always positive by design. Just an example.

Code:
static char _string[10];
static void _format( int value )
{
unsigned char tmp, tmp1;

    tmp  = value/100;
    _string[0] = '0'+tmp;
    tmp1 = value - (tmp*100);
    tmp  = tmp1/10;
    _string[1] = '.';
    _string[2] = '0'+tmp;
    tmp = tmp1 - (tmp*10);
    _string[3] = '0'+tmp;
    _string[4] =  0;
    return;
}
..or I could just printf( "proportion=%03d\n", proportion) and remember that there is a decimal place in front of the last two digits.

Last edited by dcbrown : 18-02-2007 at 11:26. Reason: add example
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting Floats, printf's, and variable maxing Tom Bottiglieri Programming 1 03-03-2005 22:35
Floats miketwalker Programming 11 02-02-2005 12:45
PRINTING OUTPUT anupalsingh Programming 7 26-02-2004 20:38
Exponenets and floats Jonbca Programming 4 31-01-2003 08:28
Printing messages archiver 1999 2 23-06-2002 22:12


All times are GMT -5. The time now is 00:23.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi