freq1 = (float)freq /10;
Serial.println(freq1,4,DEC);
i wrote this code freq value is 1005 but i want to see like 100.5
I cant, i see 100.500000000 on terminal.
What i can do hide this zeros.
freq1 = (float)freq /10;
Serial.println(freq1,4,DEC);
i wrote this code freq value is 1005 but i want to see like 100.5
I cant, i see 100.500000000 on terminal.
What i can do hide this zeros.
Give this a try:
// named constant for the pin the sensor is connected to
const int sensorPin = A0;
void setup() {
char buff[10];
Serial.begin(9600);
float freq1 = (float)1005.0 /10.0; // Note decimal values since it's floating point
Serial.print("simple print: ");
Serial.println(freq1);
dtostrf(freq1, 4, 1, buff);
Serial.print("Using dtostrf(): ");
Serial.println(buff);
}
void loop() {
}
float freq1 = freq / 10.0;
Serial.println( freq1, 1 );
When I try to compile that I get an error:
/var/folders/cs/p6yz0z1m8xj9lf0059b_lzw00000gn/T/build8828025652121218207.tmp/sketch_sep05b.cpp.o
sketch_sep05b.ino: In function 'void loop()':
sketch_sep05b.ino:36:30: error: no matching function for call to 'HardwareSerial::println(float&, int, int)'
Probably, OP forgot to make freq1 a float type.
When I try to compile that I get an error:
When you try to compile what? It would be nice to see you quote some part of the post you are referring to.
I can't see anything in any code in this thread that tries to pass three arguments to print(), so I can't imagine why the compiler is looking for a three argument version of print().
PaulS:
I can't see anything in any code in this thread that tries to pass three arguments to print(),
Look closer.
PaulS:
When you try to compile what? It would be nice to see you quote some part of the post you are referring to.I can't see anything in any code in this thread that tries to pass three arguments to print(), so I can't imagine why the compiler is looking for a three argument version of print().
freq1 = (float)freq /10;
Serial.println(freq1,4,DEC); ////////// There's the problem.
Of course I had to put the rest of a sketch in so it had a chance of compiling.
void setup() {
float freq = 1.234567;
float freq1;
freq1 = (float)freq /10;
Serial.println(freq1,4,DEC);
}
void loop() {}
Of course I had to put the rest of a sketch in so it had a chance of compiling.
Had you quoted the code, or some part of the reply containing the code, I would have known right away what code you were talking about.
And, now, back to our regular program...