# how do i get the decimal value to move postions?

Page 1 of 1

## 5 Replies - 2751 Views - Last Post: 02 August 2007 - 08:56 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=31124&amp;s=0a1b1c36b363d2ecff28f97063f5e697&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 wartech

Reputation: 10
• Posts: 203
• Joined: 16-October 06

# how do i get the decimal value to move postions?

Posted 01 August 2007 - 07:01 PM

Hi Everyone!
I have been struggling with a portion of my code. I need help understanding which data type to use to get the correct number output. Your help is appreciated.

ThankS!
```#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main()
{

int num;

cout << "F) Enter the value 612.14 " << endl;
cin >> num;
cout << "" << endl;
cout << float(num) << endl; // I would like the  value to show as 612.1400
cout << "" << endl;
cout << double(num) << endl; // I would like the value to show as 6.1214E+02
cout << endl;

system ("Pause");
return 0;

}

```

Is This A Good Question/Topic? 0

## Replies To: how do i get the decimal value to move postions?

### #2 Xing

Reputation: 19
• Posts: 725
• Joined: 22-July 06

## Re: how do i get the decimal value to move postions?

Posted 01 August 2007 - 07:26 PM

Use double or float.

### #3 wartech

Reputation: 10
• Posts: 203
• Joined: 16-October 06

## Re: how do i get the decimal value to move postions?

Posted 01 August 2007 - 07:52 PM

Xing,
I have tried that but cannot get it to work.
I have also tried different datatypes for the variable "num"

double num;
long num;
float num;

I think that it is a combination of issues such as wrong datatype for the variable "num" and the wrong datatype for the output of "num".

### #4 barnwillyb

Reputation: 6
• Posts: 108
• Joined: 22-May 07

## Re: how do i get the decimal value to move postions?

Posted 01 August 2007 - 08:22 PM

wartech, on 1 Aug, 2007 - 07:52 PM, said:

Xing,
I have tried that but cannot get it to work.
I have also tried different datatypes for the variable "num"

double num;
long num;
float num;

I think that it is a combination of issues such as wrong datatype for the variable "num" and the wrong datatype for the output of "num".

### #5 BrainStew

Reputation: 1
• Posts: 154
• Joined: 02-August 07

## Re: how do i get the decimal value to move postions?

Posted 02 August 2007 - 05:10 AM

Try something like:

```#include <iostream>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;

int main()
{

int num;

cout << "F) Enter the value 612.14 " << endl;
cin >> num;
cout << "" << endl;
cout << setprecision(4) << static_cast<float>(num) << endl; // I would like the  value to show as 612.1400
cout << "" << endl;
cout << setprecision(4) << static_cast<double>(num) << endl; // I would like the value to show as 6.1214E+02
cout << endl;

system ("Pause");
return 0;

}

```

you don't need to use the c++ style static_cast, the old c style works fine, but I like it better.

This post has been edited by BrainStew: 02 August 2007 - 07:19 AM

### #6 wartech

Reputation: 10
• Posts: 203
• Joined: 16-October 06

## Re: how do i get the decimal value to move postions?

Posted 02 August 2007 - 08:56 AM

Thanks for the replies.

I stumbled across the answers I was looking for.
```cout << "F) Enter the value 612.14 " << endl;
cin >> num;
cout << "" << endl;
cout << fixed << endl;
cout << setprecision(5)<< num<< endl;
cout << "" << endl;
cout << scientific << endl;
cout << setprecision(4) << num << endl;
cout << endl;

```

This post has been edited by wartech: 02 August 2007 - 08:57 AM