Converting millis to seconds with decimal value

Hi Guys, I have problem in converting and displaying millis into seconds with decimal value. when I divide millis by 1000 I get a round figure value. Even when I use ((value)/1000,2) also some random value will be displayed. I'm new to Arduino. Can anyone please help.

:slight_smile: :slight_smile: I Got it !! Stupid me :confused:

Serial.println((timeHold)/1000.0, 2);

lcd.print((timeHold)/1000.0, 2);

Thats all !! :sunglasses:

That still isn't correct...

millis() returns an unsigned int.

integer division results in an integer.

void setup() 
{
  Serial.begin(115200);
}

void loop()
{ 
  uint32_t currentMillis = millis();
  uint32_t seconds = currentMillis / 1000;
  int milliseconds = currentMillis % 1000;
  Serial.print(seconds);
  Serial.print(".");
  if (milliseconds < 100)
    Serial.print("0");
  if (milliseconds < 10)
    Serial.print("0");
  Serial.println(milliseconds);
}

BulldogLowell:
That still isn't correct...

millis() returns an unsigned int.

sp. "unsigned long"

AWOL:
sp. "unsigned long"

ok, unsigned long int

No, just "unsigned long". 0x00000000 to 0xffffffff
No int at all. 0x0000 to 0xffff.

Bit of a difference.

unsigned long int is OK, but it's a bit tautological.

CrossRoads:
No, just "unsigned long". 0x00000000 to 0xffffffff
No int at all. 0x0000 to 0xffff.

Bit of a difference.

this is a text sentence:

millis() returns an unsigned int.

this is code:

uint32_t currentMillis = millis();

Bit of a difference.
:wink:

What's the "_t" for?

Type.

:roll_eyes: Didnt understood a bit!! Well Im so much new to this that someone has to explain me in detail.
Attached is the full sketch. It is working fine. I need to write COUNT and TIMEHOLD to a SD card. Can someone do it for me?

LCD_Counter_Working_2_with_Serial_Print_I2C_Interface_time_Deci.ino (3.61 KB)

Welcome to the Forum. Please read these two posts:

How to use this forum - please read.
and
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Many questions can be answered by reading the documentation which is provided with the IDE, available under the help tab, or online here.

Done 8)

Guys! any solution ??

Does the code you give in reply #1 not work?

You said it was "Done 8)" so we stopped looking.

If there is still some help you need post your code (correctly in </> code tags) and say exactly what you need help with.

Steve

Code is working but I need to write the number of cycle and time hold to a sd card. can anyone update it for me please.

Code is working

What code? You seem to not understand the need to POST YOUR CODE every time you have questions about it.

but I need to write the number of cycle and time hold to a sd card

What have you tried? What happened?

can anyone update it for me please.

For the right price, yes. Helping you do it is free.

I got it . Anyway thanks