Results 1 to 7 of 7

Thread: Need help with a method for converting a double to an int in C# !

Hybrid View

  1. #1
    Join Date
    Aug 2012
    Beans
    17

    Need help with a method for converting a double to an int in C# !

    Hello fellas!

    Does anyone here know how to make a method in C# for converting a double input lets say 0.73 to make it return the int 73 ?

    Thanks in advance!

  2. #2

    Re: Need help with a method for converting a double to an int in C# !

    I don't understand your question. Is it

    1) What is the syntax to write a method in C#?

    or

    2) What algorithm would convert a floating point number, say 0.73, to the integer 73?

    1) is a homework question, just a Google search away. 2) may be pretty simple or moderately complex depending on exactly what you want to do with other numbers (e.g., what about 0.7? 0.725? 0.729999999999?)

  3. #3
    Join Date
    Aug 2012
    Beans
    17

    Re: Need help with a method for converting a double to an int in C# !

    I wonder what the algorithm would be to convert the floating point number 0.73 to integer 73.
    I want to make a method to do the operation, for example if I call my method Program.ToPercentage(0,73) the console will print just 73.

    Is it possible to start the method with:

    static int ToPercentage(double floatingpointnmbr)


    I'm very new to programming and I'm learning how to make methods in C# at the moment.
    I appreciate any help I can get!

  4. #4
    Join Date
    Jul 2010
    Beans
    91
    Distro
    Lubuntu

    Re: Need help with a method for converting a double to an int in C# !

    Quote Originally Posted by Egonosaur View Post
    I wonder what the algorithm would be to convert the floating point number 0.73 to integer 73.
    I want to make a method to do the operation, for example if I call my method Program.ToPercentage(0,73) the console will print just 73.

    Is it possible to start the method with:

    static int ToPercentage(double floatingpointnmbr)


    I'm very new to programming and I'm learning how to make methods in C# at the moment.
    I appreciate any help I can get!
    What should be the output of Program.ToPercentage(0.731)? Should it print 731, 73, or the non integer number 73.1? The name of the function would suggest that what you need is to multiply the number by 100.
    - What do you get if you multiply six by nine?
    - 42!

  5. #5
    Join Date
    Aug 2012
    Beans
    17

    Re: Need help with a method for converting a double to an int in C# !

    Quote Originally Posted by Odexios View Post
    What should be the output of Program.ToPercentage(0.731)? Should it print 731, 73, or the non integer number 73.1? The name of the function would suggest that what you need is to multiply the number by 100.

    I want the program to print out the integer 73

  6. #6

    Re: Need help with a method for converting a double to an int in C# !

    You'll get better responses if you start by trying to write code and post what you have when you run into problems. Even if it doesn't work, it shows you're serious about putting in the effort and aren't just trying to get free answers for your homework.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •