Determines whether the input is a floating point number.

Source: Internet
Author: User
Determines whether the input is a floating point number.
When editing a VC program, the number of Float entries is often controlled. If the input box is set to float, it can meet the requirements, but it may encounter some difficulties in real-time control, for example, the decimal point cannot be entered.
Therefore, it is more convenient to set it to the cstring type and write a function for control.
In this way, you can easily control the number of decimal places after which only a few decimal places can be entered.
Its function is
Bool cisfloatdlg: isfloat (cstring & STR, int ID)
{
Int dotflag = 0;
// Whether it is a floating point number
For (INT I = 0; I <Str. getlength (); I ++)
{
If (STR [I] = '.')
Dotflag ++;
If (dotflag> 1) // more than one decimal point
|
! (STR [I] = '. ') | (STR [I]> = '0' & STR [I] <= '9') // The number entered is not. 0-9
)
{
MessageBox ("not a number ");
(Cedit *) getdlgitem (ID)-> setsel (0,1000, true );
Return false;
}
}
// Only two decimal places can be entered
Int dotposition = Str. Find (".");
If (dotposition! =-1)
{
STR = Str. Left (dotposition + 3); // Delete the last position
Updatedata (false );
(Cedit *) getdlgitem (ID)-> setsel (, false); // The focus is at the end.
Return false;
}
Return true;
}
Original code download http://download1.csdn.net/down3/20070610/10104714439.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.