# How to limit volt display to whole #'s only?

Hello,

I’m looking for some code modification that will only print whole numbers when I display the voltage of the volt meter code I’m using to my 4x20 lcd. Here is a link to the volt meter code I’m using here. At the present time I’m using if statements to block out the decimal point and the the proceeding 2 numerical charters by printing blank spaces to the lcd where the decimal numbers appear. Is there a way to modify this volt meter code below to only calculate whole numbers? Maybe by rounding off? Any help will be greatly appreciated.

Thanks
jessey

``````    /*
DC Voltmeter
An Arduino DVM based on voltage divider concept
T.K.Hareendran
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!
int value = 0;
void setup(){
lcd.begin(16, 2);
lcd.print("DC VOLTMETER");
}
void loop(){
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09) {
vin=0.0;//statement to quash undesired reading !
}
lcd.setCursor(0, 1);
lcd.print("INPUT V= ");
lcd.print(vin);
delay(500);
}
``````

Decide if you want to truncate or round.

(deleted)

``````lcd.print(vin, 0);
``````

Please take a few minutes to at least read a little of the documentation before you just come and ask. This is covered explicitly in the docs for print.

spycatcher2k:

``````lcd.print(vin);
``````
``````lcd.print(int(vin+0.5));
``````

Thanks spycatcher2k,

That does exactly what I needed.

Thanks Again
jessey

aarg:
Decide if you want to truncate or round.

Thanks for getting back to me aarg,

Is this code that spycatcher2k sent (lcd.print(int(vin+0.5)) truncating or rounding off vin?
Can you explain the differences.

Thanks
jessey

Truncate means just cut off the decimal. 2.34 becomes 2 and 4.87 becomes 4.

Rounding means just what it does in math. 2.34 still becomes 2 but 4.87 now becomes 5.

It’s just like it was in third grade math class.

Hi,
If you wants to truncate the number just change the variable float vin to int vin. That will change the variable from floating to interger.