Can't get frac to correctly display after decimal point

I can’t get frac to display anything to the right of the decimal point. I am a total newb so may have int & float not working together correctly.

This is my first attempt at at using my own equations rather than using other peoples’s sketch and it is not going well, what the frac…lol.

Hardware: Arduino Uno R3, Adafruit standard 20X4 lcd with i2c backpack, Adafruit RTC.

In the sketch attached the equation is (219*17)/4=930.75. Instead I get 930.0… I can’t get the value to the right of the decimal to display correctly. I have tried using other values for rw, dist and acre and always get erroneous info to the right of the decimal point. The int, the number to the left of the decimal point is always correct???

Have used frac in a flow meter application with success but can’t get frac to work with my equation here.

I have commented out the RTC code with // and there is no difference. I have left in my comments behind // throughout the sketch.

I’m sure it is an obvious error, but not being bothered by much knowledge of C or C++ I can’t see it.

Here is my pitiful sketch:

  // include the library code:
  #include <Wire.h>
  #include "RTClib.h"
  #include <LiquidCrystal.h>

  // initialize the library with the numbers of the interface pins
  LiquidCrystal lcd(0);

  RTC_DS1307 rtc;
  int rw = 219;
  int dist = 17;
  int acre = 4;
  float k;
  unsigned int frac;
  void setup() {
  lcd.begin(20, 4);
  Serial.begin(57600);  // changing this doesn't seem to matter 9600 or 57600

  void loop() {
  DateTime now =;
  lcd.setCursor(15, 0);
  lcd.print(now.hour(), DEC);
  lcd.print(now.minute(), DEC);

  k = AcreageCalculation(rw, dist, acre); // when this is // out then Acre=0.00
   lcd.setCursor(0, 2);
   lcd.print(int(k), DEC);  //removing the DEC has no effect, here or two lines below
   lcd.print(".");  // without this whole number only
   frac = (k - int(k)) * 10;  // without this whole number only int.0 no matter if 10 or 1000
   lcd.print(frac, DEC);  // without this whole number only
   //lcd.print(k, 2);  // thes give int.00 if 2  or .000 if 3 but no remainder
   delay (10);
   float AcreageCalculation(int rw, int dist, int acre){
   float result;
   result = (rw * dist / acre);
   return result;   // displays 930.0 instead of 930.75

Thanks in advance for any and all help.

result = (rw * dist / acre);

Since everything on the right is an int, the math gets done with int so there is no fraction part. Then it gets assigned to a float but the fraction part is already gone.

Try this instead, cast one of them to float so the math gets done with float math:

result = ((float)rw * dist / acre);

Thank you soooo much...and such fast correct answer..I will never admit how much time I spent/wasted on this before I posted my plea for help....I will never beat my head against the proverbial wall for soo long ever again....these forums are the best!

My project has many more similar calculations which guarantees my return here for more help.

Thanks from a very grateful California farmer!