Division Console output with a comma not rounded [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Is there a way for the console output to be a decimal number with a comma my output is always rounded and i can barely us it like this.
Int a = 90 ;
Int b = 7;
Int c = a/b;
This out puts 13 not the actual value.

It is advice rewritten from my comment:
Please check any elementary C++ tutorial :) For your information there isn't bult-in type Int in C++, so it seems that you want to ask about int type division. The answer could be: store your result in some floating point type as float :)
You're welcome!

use float or double instead. int will never provide you with decimals.
Example:
float a=90,b=7;
float c = a/b;
printf("%.2lf",c);
The code avobe mentioned will write 2 decimals. If you want more, just change the 2 here %.2lf for your amount of decimals required.

Related

Convert the binary number into base 2 scientific notation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 17 days ago.
Improve this question
Sorry, maybe my explanation is not understandable (edit).
enter image description here
in the figure, to shorten the number, we use scientific notation, but shouldn't we use
a x 10^n
however in the image, using
a x 2^n
why use base 2.
isn't it if we add base 10 the right answer
this is the result if i use
a x 2^n
enter image description here
(it is not in accordance with)
this is the result if i use
a x 10^n
enter image description here
Thankyou for answer
In base 10, 1.010101001d x 10d^6 = 1010101.001d
In base 2, 1.010101001b x 10b^6 = 1010101.001b (but 10b = 2d)

(C++)trying to convert double to integer (explaining) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
saw this in an example
double x = 50.2
cout << (double)(int)(x);
this works fine , and also it works without the (double) ,
so why adding the (double) there?
You don't have to add (Double) there, why indeed. You are converting 50.2 to int wich evaluates to 50, then you are converting 50 back to double wich stays at 50 If you print it. The only reason i can think to do this is If it's inside some function with a return double value or to extract the integer part of a Double value, but it's not a good practice at all.

C++ full number of degree [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is a simple code that counts two to the right degree. Starting from somewhere around 60 degrees the answer is incorrect.
I need to count 2^200. The answer shouldn't be in the form like "1.606938e+60", but by numbers. How to do this in C++?
#include <iostream>
using namespace std;
int main()
{
unsigned long long int n,z;
cin>>n;
z=pow(2,n);
cout<<z<<endl;
return 0;
}
You need to use std::set_precision(n) to get it to print in the format that you're expecting it, but if your numbers get high enough, you'll run into a second issue. pow returns a double, which loses precision in a big way with huge numbers. For more information on how to solve that, refer to this Stack Overflow answer.
Anyway you cant print such big number as a single integer or double value in c++ (not yet). Maybe there exist some 256 or 512 machine architectures and implementations which build in types are large enough, but its not possible in common. You probably need to use some data structure to store you number and operate on that.
This, this and this examples may be helpful.

increase long double accuracy [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
how can I increase accuracy in double.
for example in this code:
#include <stdio.h>
int main() {
long double a = (long double) 5 / 3;
printf("%.62LLF", a);
return 0;
}
Floating Point Numbers have a limited precision. Mandatory Reading Here.
The boost.multiprecision library can give you access to higher precision floating point numbers, whether in the form of quad types which simply double the precision of double, or in the form of arbitrary precision rational numbers. If you're willing to take the time to learn how to install and use that library, you'll be able to improve the precision of your numbers.

How do I make a basic c++ calculator calculate decimals [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a decent grasp with c++, and I made a basic calculator that can add, subtract, multiply, and divide. but I am having a hard time trying to get it to calculate decimals. Help please???
Read http://floating-point-gui.de/ first.
You don't calculate decimals, you display a floating point number (often some double) with some decimals.
Use things like std::showpoint & std::fixed ...
If you want to show a lot of correct digits, you need to do arbitrary precision arithmetic or BigNums. Then use a library, such as GMPlib