float与Int的问题
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
/*
Template designed by RuPeng.com. Please visit http://www.rupeng.com for more information
如鹏网(http://www.rupeng.com)大学生计算机学习社区,提供大量免费视频学习教程,提供个性化一对一学习指导
*/
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}
return FALSE;
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
return TRUE;
}
BOOL isfloat(TCHAR *a)
{
float b = atof(a);//为什么这里用float后,程序不能帅选是数字,但是用int就可以了?
TCHAR c[256];
wsprintf(c,"%d",b);
if(strcmp(c,a)!=0)
{
return FALSE;
}
else
{
return TRUE;
}
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
TCHAR str1[256],str2[256];
GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1));
GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2));
if(isfloat(str1)==FALSE)
{
MessageBox(hwnd,TEXT("错误"),TEXT("1单元非法字符"),NULL);
return;
}
if(isfloat(str2)==FALSE)
{
MessageBox(hwnd,TEXT("错误"),TEXT("2单元非法字符"),NULL);
return;
}
float str1temp = atof(str1);
float str2temp = atof(str2);
float str3temp = str1temp-str2temp;
TCHAR a[256];
sprintf(a,"%f",str3temp);
SetDlgItemText(hwnd,IDC_EDIT3,a);
}
break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
/*
Template designed by RuPeng.com. Please visit http://www.rupeng.com for more information
如鹏网(http://www.rupeng.com)大学生计算机学习社区,提供大量免费视频学习教程,提供个性化一对一学习指导
*/
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}
return FALSE;
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
return TRUE;
}
BOOL isfloat(TCHAR *a)
{
float b = atof(a);//为什么这里用float后,程序不能帅选是数字,但是用int就可以了?
TCHAR c[256];
wsprintf(c,"%d",b);
if(strcmp(c,a)!=0)
{
return FALSE;
}
else
{
return TRUE;
}
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
TCHAR str1[256],str2[256];
GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1));
GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2));
if(isfloat(str1)==FALSE)
{
MessageBox(hwnd,TEXT("错误"),TEXT("1单元非法字符"),NULL);
return;
}
if(isfloat(str2)==FALSE)
{
MessageBox(hwnd,TEXT("错误"),TEXT("2单元非法字符"),NULL);
return;
}
float str1temp = atof(str1);
float str2temp = atof(str2);
float str3temp = str1temp-str2temp;
TCHAR a[256];
sprintf(a,"%f",str3temp);
SetDlgItemText(hwnd,IDC_EDIT3,a);
}
break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
...全文
相关推荐
short int、long、float、double使用问题说明
在Access数据导出到DBF时遇到此问题,DBF中的字段宽度不是指Access中的字段所占字节数,而是字符数。
解决java数值范围以及float与double精度丢失的问题
下面小编就为大家带来一篇解决java数值范围以及float与double精度丢失的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Test_int_to_float.rar_float
Test int to float Source Code for Andriod.
C语言中int到float的强制类型转换
最近项目中经常需要int与float之间转换,有必要对它们之间转换的原理做个了解。
Go语言string,int,int64 ,float之间类型转换方法
Go语言中int类型和string类型都是属于基本数据类型,两种类型的转化都非常简单。下面通过本文给大家分享Go语言string,int,int64 ,float之间类型转换方法,感兴趣的朋友一起看看吧



