Baxter
Baxter

Reputation: 5845

Int to Decimal Conversion - Insert decimal point at specified location

I have the following int 7122960
I need to convert it to 71229.60

Any ideas on how to convert the int into a decimal and insert the decimal point in the correct location?

Upvotes: 27

Views: 110607

Answers (3)

dennis
dennis

Reputation: 2020

Declare it as a decimal which uses the int variable and divide this by 100

int number = 700
decimal correctNumber = (decimal)number / 100;

Edit: Bala was faster with his reaction

Upvotes: 4

yoozer8
yoozer8

Reputation: 7489

Simple math.

double result = ((double)number) / 100.0;

Although you may want to use decimal rather than double: decimal vs double! - Which one should I use and when?

Upvotes: 5

Bala R
Bala R

Reputation: 108957

int i = 7122960;
decimal d = (decimal)i / 100;

Upvotes: 63

Related Questions