BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 06-10-2009, 05:25 PM   #1 (permalink)
itp
Knows Where the Search Button Is
 
Join Date: Jul 2008
Model: none
PIN: N/A
Carrier: none
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default round()

Please Login to Remove!

I am looking for a round function compatible back to JDE 4.3. If it does not exist, can someone help me with a custom function?

example: round(long numer, int precision)

thanks
Offline  
Old 06-12-2009, 12:51 PM   #2 (permalink)
itp
Knows Where the Search Button Is
 
Join Date: Jul 2008
Model: none
PIN: N/A
Carrier: none
Posts: 24
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK. I cobbled this together. It works, but is not very idiomatic or efficient. Comments and suggestions welcome...

PHP Code:
       public static double round(double numberToRoundint precision)
        {
            
double coefficient Math_.pow(10precision);
            
double numXcoef numberToRound coefficient;
            
            
// get value left of decimal    
            
String sTempValue numXcoef "";
            
int decPos sTempValue.length();
            for ( 
int i 0sTempValue.length(); i++ ) 
            {
                
char c sTempValue.charAt);
                if(
== '.')
                {
                    
decPos i
                }     
            }
            
String sLeftOfDecimal sTempValue.substring(0,decPos); 
            
double LeftOfDecimal Double.valueOf(sLeftOfDecimal).doubleValue();
            
            
// Isolate right side of decimal (RightOfDecimal)
            
String sRightofDecimal sTempValue.substring(decPos,sTempValue.length());
            
double RightOfDecimal Double.valueOf(sRightofDecimal).doubleValue();
            
            
// if greater than or equal to .5, then bump up value returned 
            
if(RightOfDecimal >= .5)
            {
                
LeftOfDecimal LeftOfDecimal 1;              
            }
            
            
LeftOfDecimal LeftOfDecimal coefficient;
            return 
LeftOfDecimal;
        } 
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Trafag Pressure Transducer 8894.23.3315 -1.. 2.5 bar 4..20mA 10...34V DC G1/4
$95.0
Trafag Pressure Transducer 8894.23.3315 -1.. 2.5 bar 4..20mA 10...34V DC G1/4 picture1PC Brand New In Box Novotechnik Transducer LWG-0150 LWG0150
$410.0
1PC Brand New In Box Novotechnik Transducer LWG-0150 LWG0150 picture SETRA Pressure Transducer for Quincy Compressor 209140.08.QCY
$95.0
 SETRA Pressure Transducer  for Quincy Compressor  209140.08.QCY picture920128 AMETEK SOLARTRON DC50 LVDT Displacement Transducer
$750.0
920128 AMETEK SOLARTRON DC50 LVDT Displacement Transducer pictureGE Corometrics Nautilus 5700HAX 5700LAX Ultrasound Transducer Circuit Board New
$29.99
GE Corometrics Nautilus 5700HAX 5700LAX Ultrasound Transducer Circuit Board New picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.