cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
How to not display decimal points
How to not display decimal points
May 5, 2013 at 8:25pm UTC
Tstan
(19)
While trying to make a basic code to convert and display temperature, I need the program to show no decimal places so I use cout.precision(0) when I do that it gives me scientific notation
Example
2e-02 when I simply want it to drop the .22 of 22.22
May 5, 2013 at 8:34pm UTC
jidder
(139)
You could just cast it to an int.
cout <<
"Temp:"
<<
static_cast
<
int
>(temprature);
May 5, 2013 at 8:39pm UTC
Chervil
(7320)
Cast to int will truncate, if the value was 18.89, it would be better to round it up.
Try
cout << fixed;
or
cout.setf(ios::fixed);
, this affects the way the precision is interpreted.
May 5, 2013 at 8:40pm UTC
Tstan
(19)
It is for a school assignment. So I have to use certain basic codes. Else that would work!
May 5, 2013 at 8:41pm UTC
Ispil
(788)
You could use cmath and the ceiling/floor functions.
May 5, 2013 at 8:42pm UTC
jidder
(139)
@chevril
What do fixed and cout.setf(ios::fixed) do ?
edit: nvm looked it up.
Last edited on
May 5, 2013 at 8:52pm UTC
May 5, 2013 at 8:44pm UTC
Tstan
(19)
Thanks guys that works!!
May 5, 2013 at 8:54pm UTC
Chervil
(7320)
@jidder
http://www.cplusplus.com/reference/ios/ios_base/fmtflags/
http://www.cplusplus.com/reference/ios/ios_base/precision/
Topic archived. No new replies allowed.