On-line: гостей 0. Всего: 0 [подробнее..]
Программисты всех стран, объединяйтесь!

АвторСообщение



ссылка на сообщение  Отправлено: 05.07.14 09:37. Заголовок: how to find float decimal palce


i like to compare two float value the decimal place are matching
eg float values 0.02541 , 0.06541 . if i multiply one of this value like --> 0.02541 * 100000 = 2541 so this value have 4 decimal place how can i find this

Спасибо: 0 
ПрофильЦитата Ответить
Ответов - 12 [только новые]





ссылка на сообщение  Отправлено: 06.07.14 09:50. Заголовок: solved


i wrote this code . is this code good or bad is there any better way to do this

#include <iostream>
#include <sstream>
using namespace std;

int main () {

float val =1.1006;
val = val*10000;

cout<<val<<endl;
stringstream ss (stringstream::in | stringstream::out);

ss << val;

string test = ss.str();

cout << test <<endl;
std::cout << "The size of str is " << test.size() << " bytes.\n";

return 0;
}

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 08.07.14 01:18. Заголовок: The code is compiled..


The code is compiled successfully but it is not clear what you are trying to achieve.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 08.07.14 08:18. Заголовок: i am tying to compar..


i am tying to compare two float value that have same decimal place like this --> 0.12451 value have 5 decimal value ,---> this 0.00214 value have 3 decimal . i like to know is there any other way to do this

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 08.07.14 14:56. Заголовок: I have not understoo..


I have not understood what you mean saying that 0.00214 has 3 decimal.

Maybe you will find function modf declared in header cmath useful for yourself. It allows to extract the fraction of a floating number. For example

 
#include <iostream>
#include <cmath>


int main ()
{
double val = 1.1006;

double ipart;

double fpart = std::modf( val, &ipart );

std::cout << ipart << '\t' << fpart << std::endl;

return 0;
}

The output is
 
1 0.1006


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 08.07.14 18:36. Заголовок: no this is not i ne..


no this is not i needed . in my way you can see (above code) that i first multiply value like 0.00214 * 100000 = 214 i multiply to remove unwanted zero from value then i want to count how many value position like 0th , 10th, 100th, or 1000th in this case 214 is 100th so it is 3 . then i want to compare check to next value that is matching or not

above code that i convert float to string and use .size() operator to find this value. i like to know any better way to do this


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 09.07.14 21:15. Заголовок: Instead of std::stri..


Instead of std::stringstream you could use function std::to_string.

Спасибо: 1 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 10.07.14 11:15. Заголовок: :sm36: ..




Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 13.07.14 15:51. Заголовок: float to string convertion precision


std::stringstream & std::to_string are working correct . but when i input big precision value like float a = 3.141593254 its rounding value 3.14159 so it's not converting full float value to string i need 11 value precision and i can't use std::to_string becouse its c++ 11 fetures

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 14.07.14 14:41. Заголовок: The problem is that ..


The problem is that float numbers of type float are outputed with 6 decimal digits while float numbers of type double are outputed with 15 decimal digits.

Consider the following code
 
#include <iostream>
#include <iomanip>
#include <limits>


int main()
{
float a = 3.141593254;
double b = 3.141593254;

std::cout << std::numeric_limits<float>::digits10 << std::endl;
std::cout << "a = "
<< std::setprecision( std::numeric_limits<float>::digits10 )
<< a << std::endl;
std::cout << std::numeric_limits<double>::digits10 << std::endl;
std::cout << "b = "
<< std::setprecision( std::numeric_limits<double>::digits10 )
<< b << std::endl;

return 0;
}


The output is
 
6
a = 3.14159
15
b = 3.141593254


Take into account that in this statement
 
float a = 3.141593254;

the float literal used as initializer has type double while variable a has type float. So there is a loss of precision.


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 14.07.14 22:14. Заголовок: i need to do this in..


i need to do this in float because my array data , i accessing like const float* rIn = in[rchan] + x; i believe this is 32 bit float array
is there any other way of doing this
i tried to convert float to string and float to char array both code working but it did not get 11 precision

all i want to do is look in the float value a left to right a = 0.001590254; in this case 0 to 4 and remove all the zero until any other value found and count how many digits in there so in this --> (1590254) 1 to 4 is the 7 digits size i like to get this size

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 14.07.14 22:42. Заголовок: data type float has ..


data type float has a restriction on the number of decimal digits it can store. If you have an array of float numbers then it can not represent exactly values as 0.001590254.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.07.14 08:26. Заголовок: so i need to find ot..


so i need to find other way

Спасибо: 0 
ПрофильЦитата Ответить
Ответ:
1 2 3 4 5 6 7 8 9
большой шрифт малый шрифт надстрочный подстрочный заголовок большой заголовок видео с youtube.com картинка из интернета картинка с компьютера ссылка файл с компьютера русская клавиатура транслитератор  цитата  кавычки моноширинный шрифт моноширинный шрифт горизонтальная линия отступ точка LI бегущая строка оффтопик свернутый текст

показывать это сообщение только модераторам
не делать ссылки активными
Имя, пароль:      зарегистрироваться    
Тему читают:
- участник сейчас на форуме
- участник вне форума
Все даты в формате GMT  3 час. Хитов сегодня: 19
Права: смайлы да, картинки да, шрифты да, голосования нет
аватары да, автозамена ссылок вкл, премодерация откл, правка нет