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

#### Hybrid View

1. Spilled the Beans
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 ?

2. Tall Cafè Ubuntu
Join Date
Feb 2009
Beans
1,468

## 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. Spilled the Beans
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. ## Re: Need help with a method for converting a double to an int in C# !

Originally Posted by Egonosaur
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.

5. Spilled the Beans
Join Date
Aug 2012
Beans
17

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

Originally Posted by Odexios
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. Tall Cafè Ubuntu
Join Date
Feb 2009
Beans
1,468

## 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.