calc minutes to houre

Posted on 2007-10-01
Last Modified: 2010-05-18
time calc problem
i have this resuat of time :
its need to be 11 hours
the .60 is minutes
its need to be turn to 1 houre
i do this code ant its work good :

decimal time =(decimal)10.60;
decimal t = time % 2;
textBox2.Text = t.ToString();
decimal res =(t/60) * 100;
time = time - t;
decimal tot = time + res;

now if the total hour is 10.70 insted of 10.60
i need to get 11 hours and 10 min = 11.10
i am geting wrong resualt 11:16

how can i fix that ?
thanks ...
Question by:Tech_Men
    LVL 21

    Expert Comment

    Generally what are you using this code for? what are you trying to do ?

    Author Comment

    i mange but i still have a small problem
    if the diff is a round number
    i need to add the number .00

    i need to check if the num is round and if he is round i need to attach the .00
    if i get the num 8
    i need to change it to 8.00
    LVL 21

    Expert Comment

    If you are looking to check if the number is round. you should look at Math.Round() function
    LVL 22

    Accepted Solution

    This will do what you want:
    decimal time = (decimal)10.70;
    int hours = (int)time;
    time = time - hours;
    int minutes = (Convert.ToInt32(time * 100));
    int extraHours = minutes / 60;
    minutes = minutes % 60;
    int totalHours = hours + extraHours;
    time = Convert.ToDecimal(totalHours) + Convert.ToDecimal(minutes ) /100;


    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now