Pages: [1]   Go Down
Author Topic: Variable precision printing of floats  (Read 452 times)
0 Members and 1 Guest are viewing this topic.
Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been using this function from the Print library to print floats:

Code:
void Print::printFloat(double number, uint8_t digits)

It is currently a private, but is making it available to the Print class as simple as moving it down into the publics in Print.h?
Logged

Toronto, ON
Offline Offline
Full Member
***
Karma: 10
Posts: 233
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep.

b
Logged


Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cool. And if I delete Print.cpp.o, it will recompile automagically?
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16464
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yep
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are going to modify the class, adding the following two methods are a more consistent way of getting the functionality you are looking for (of course you need to declare these in the h file as well)

Code:
void Print::print(double n, uint8_t digits)
{
  printFloat(n, digits);
}

void Print::println(double n, uint8_t digits)
{
  printFloat(n, digits);
  println();
}
I expect the Arduino team will be supporting user settable precision in future using this syntax.
« Last Edit: July 22, 2009, 10:12:04 pm by mem » Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, that preserves the orthogonality. That's the way I'll do it.

Quote
I expect the Arduino team will be supporting user settable precision in future using this syntax

And maybe even the Reference page as well... smiley-wink
Logged

Pages: [1]   Go Up
Jump to: