vc arbitrary bit string, said the figures rounded to the nearest decimal places to retain and

sponsored links
BOOL SHGlobal::isIntOrDecimal(CString strItem)
{
        //  Determine whether an integer or decimal  
        //  Returns 0 for not  
        //  Returns the integer 1 representative  
        //  Returns 2 represents decimal  
        if(strItem.IsEmpty())
                return FALSE;
        
        for(int i = 0; i <strItem.GetLength(); i++) 
        { 
                //   check "+ ". "- " 
                if(i == 0 && (strItem.GetAt(i) == 0x2B || strItem.GetAt(i) == 0x2D)) 
                        continue; 
                
                //   check   char 
                if( !isdigit(strItem.GetAt(i)) && strItem.GetAt(i) != '.') 
                        return   FALSE; 
    } 
        
    //   check    Decimal point   
    if(strItem.Find( '.') != strItem.ReverseFind( '.')) 
        return FALSE; 
        
      return TRUE;
}

// tS  A string that represents the manipulation  
// tDecimalCount  Indicates the need to retain the number of decimal places  
// tRound  Indicates whether the rounding operation  
// addLenWhenLarger  Represents were rounded exceeds the current length of the range of digits that are added  
CString SHGlobal::strRound(CString tS, int tDecimalCount, boolean tRound, boolean addLenWhenLarger)
{
        if(!isIntOrDecimal(tS))
                AfxMessageBox(_T(" Illegal numbers cannot be formatted  "));
        
        int strLen = tS.GetLength();
        int dotIndex = tS.Find('.');    //  The location of the decimal point  
        int i = 0 ;

        if(dotIndex < 0 && tDecimalCount <= 0)//  The integer itself and does not require decimal places  
        {}
        else if(dotIndex < 0 && tDecimalCount > 0)        //  Itself is an integer, but the need to increase the number of decimal places  
        {
                tS += ".";
                for(i =0 ; i < tDecimalCount; i++)
                        tS += "0";
        }else if(dotIndex > 0 && dotIndex + tDecimalCount + 1 >= strLen)  
                //  Itself a small number of decimal digits but is less than or equal to the number of decimal places you want to keep  
        {
                int tDots = (dotIndex + tDecimalCount + 1) - strLen;
                for(i =0 ; i < tDots; i++)
                        tS += "0";
        }else if(dotIndex > 0 && dotIndex + tDecimalCount + 1 < strLen){
                //  Itself a decimal and decimal is greater than the number of decimal places you want to keep, you need to format  
                if(!tRound){
                        //  You do not need to round up  
                        tS = tS.Mid(0, dotIndex + tDecimalCount + 1);
                }
                else{
                        //  You need to round up  
                        if(tS.GetAt(dotIndex + tDecimalCount + 1) < '5'){
                                //  Keep the number of decimal places after a bit of less than five  
                                tS = tS.Mid(0, dotIndex + tDecimalCount + 1);
                        }else{
                                //  From the last bit forward to carry judgment  
                                tS = tS.Mid(0, dotIndex + tDecimalCount + 1);
                                boolean needtoAdd = TRUE;       //  Is there a carry  
                                for(i = tS.GetLength() - 1; i >=0 ; i--){
                                        if(needtoAdd){
                                                char tCC = tS.GetAt(i);
                                                if(tCC == '.')
                                                        continue;
                                                tCC++;
                                                if(tCC > '9'){
                                                        //  Produce a carry  
                                                        tCC = '0';      
                                                        tS.SetAt(i,tCC);
                                                        needtoAdd = TRUE;
                                                }else {
                                                        needtoAdd = FALSE;
                                                        tS.SetAt(i,tCC);
                                                        break;
                                                }
                                        }
                                }
                                if(needtoAdd && addLenWhenLarger){
                                        //  When the first also need when rounding up and allows when rounding up  
                                        tS = "1" + tS;
                                }
                        }
                }
        }

        return tS;

}
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of vc arbitrary bit string, said the figures rounded to the nearest decimal places to retain and

  • Hibernate configuration parameters hibernate.hbm2ddl.auto

    Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • can not be represented as java.sql.Timestamp

    Development of procedures for the use of hibernate when, some time there is no need to fill in the fields, but after the hibernate query time reported "Java.sql.SQLException: Value'0000-00-00 'can not be represented as java.sql.Timestamp ...

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

  • Great collection of java interview topics

    1, object-oriented features of what has 1. Abstract: Abstract is that it has overlooked a subject has nothing to do with the current goal of those aspects in order to more fully with the current objectives of the attention-related aspects. Abstract does n

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries