사용자 도구

사이트 도구


사이드바

카테고리

language:cpp:코드_조각

정수부를 모두 가수부로 내리는 코드

이런 식으로

88 -> 0.88
1910 -> 0.191
#include <strsafe.h>
#include <stdio.h>
#include <math.h>
 
{
int _n = 705;
int _ncnt = ((int)log10((float)_n)) + 1; // 제곱수 구하기. 1을 더해서 자리수 얻기
float _v = pow(0.1f, _ncnt);             // 0.1 을 자리수만큼 제곱
float _f = _n * _v;                      // 0....1 만들어진걸로 곱해서 0.이하로 이동
 
//int _n = 705;
//float _f = _n * pow(0.1f, (((int)log10((float)_n)) + 1));
 
// 결과 출력
//TCHAR _fout[MAX_PATH]; ZeroMemory(_fout, MAX_PATH);
//StringCbPrintf(_fout, MAX_PATH, L"final out: %f \n", _f);
//MessageBox(NULL, _fout, L"Test Result", MB_OK); 
}
language/cpp/코드_조각.txt · 마지막으로 수정됨: 2022/12/07 22:30 저자 kieuns