Hey, so im having this little problem. The answer is without 8 at the end. It prints me 0.1234567. There is no 8 at the end even tho it should be. Any ideas?
-Thanks!!!! :)
[CODE]cout << 12345678.0 / 100000000.0 << endl; // Answer is without 8 at the end[/CODE]
[QUOTE=Edvinas;47461424]Try this:
[code]
#include <iostream>
#include <iomanip>
...
double number = 12345678.0 / 100000000.0;
std::cout << std::fixed << std::setprecision(8) << number << std::endl;
[/code][/QUOTE]
Deja, nepadejo. :D Be to seprecision neveiktu man, nes reikia, kad nei vienas skaicius nedingtu is savo vietu, nes as alikineju veiksmus veliau su tuo NUMBER.
[QUOTE=Matkenis;47461550]Deja, nepadejo. :D Be to seprecision neveiktu man, nes reikia, kad nei vienas skaicius nedingtu is savo vietu, nes as alikineju veiksmus veliau su tuo NUMBER.[/QUOTE]
It should work, just tested this. Also the number inside the memory is kept with all the decimal places you need. Though when you print it cout rounds it so you have to tell it to do otherwise. If cout were to print the whole number, it could be crazy long.
For example:
[code]
double num2 = 333.33;
std::cout << std::setprecision(40) << num2;
// Would print:
// 333.3299999999999840838427189737558364868164
[/code]
[QUOTE=Edvinas;47461582]It should work, just tested this. Also the number inside the memory is kept with all the decimal places you need. Though when you print it cout rounds it so you have to tell it to do otherwise. If cout were to print the whole number, it could be crazy long.
For example:
[code]
double num2 = 333.33;
std::cout << std::setprecision(40) << num2;
// Would print:
// 333.3299999999999840838427189737558364868164
[/code][/QUOTE]
Setprecision tik spausdinimui... O man reikia naudoti ji toliau, 8 - etas dingsta, kurio man reikia..
Speak English, nobody understands you.
[QUOTE=cartman300;47461897]Speak English, nobody understands you.[/QUOTE]
Oh, well sorry. The problem is that my 8 dissapears, i actually need it. Because im doing more calculations with those digits. So how do i modify this so that i would stay and not dissapear?
The digit 8 is still there, the std::cout just doesn't display it by default. You can do your further calculations just fine.
[code]
#include <iostream>
#include <iomanip>
int main()
{
double number = 12345678.0 / 100000000.0;
// Now if you print the number like this, it gets rounded, so you don't see the 8.
// The number still contains digit 8, it just doesn't display that.
std::cout << number << std::endl;
// To counter that, you have to specifiy how many decimal places to display.
std::cout << std::setprecision(7) << number << std::endl;
// Just to show that 8 is still in place.
double newNumber = number * 100000000.0;
std::cout << std::fixed << std::setprecision(1) << newNumber << std::endl;
return 0;
}
[/code]
[QUOTE=Edvinas;47462067]The digit 8 is still there, the std::cout just doesn't display it by default. You can do your further calculations just fine.
[code]
#include <iostream>
#include <iomanip>
int main()
{
double number = 12345678.0 / 100000000.0;
// Now if you print the number like this, it gets rounded, so you don't see the 8.
// The number still contains digit 8, it just doesn't display that.
std::cout << number << std::endl;
// To counter that, you have to specifiy how many decimal places to display.
std::cout << std::setprecision(7) << number << std::endl;
// Just to show that 8 is still in place.
double newNumber = number * 100000000.0;
std::cout << std::fixed << std::setprecision(1) << newNumber << std::endl;
return 0;
}
[/code][/QUOTE]
Yeah, well thanks. Already found it. :)
[QUOTE=Rocket;47464448]Can we stop rating this guy dumb for speaking in Lithuanian with a Lithuanian person?[/QUOTE]
This is an english forum. What if someone has the same problem, and finds this thread? If they can't speak Lithuanian, that's a real bummer for them.
Also, for the same reason, would you mind posting the solution you found for your problem?
[QUOTE=Rocket;47465784]Yeah but we're rating him dumb on posts where he's speaking English.[/QUOTE]
Yah that's pretty dumb. Zing.
Anyways, Like Darkwater mentioned this should've only been rated on the lithuanian post.
Sorry, you need to Log In to post a reply to this thread.