pgega  
              
                  
                    September 17, 2007,  1:24pm
                   
                  1 
               
             
            
              Hi there
I am going to calculate VAT at one of my websites, and UK VAT is 17.5
I often get values like 6,991…
In php I was using round function
round($price, 2)
is in ruby something similat to PHP’s round function where I could
P.
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 17, 2007,  1:24pm
                   
                  2 
               
             
            
              On 9/16/07, pgega [email protected] 
Hi there
I am going to calculate VAT at one of my websites, and UK VAT is 17.5
 
one way is to use   round(n * 100) / 100.0
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 25, 2007, 11:01pm
                   
                  3 
               
             
            
              n would be your number, then multiplying it by 100 and rounding it would
n = 12.3456
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 25, 2007, 11:02pm
                   
                  4 
               
             
            
              On Sep 16, 8:54 am, pgega [email protected] 
Thanks,
And which part of the code corresponds for the number of decimal
in Ruby, it is like   (n * 100).round / 100.0
 
 
it is like   (n * 102).round / (10 2).to_f
the 2 is the one you want and 10**2 is 10 to the power of 2.
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 25, 2007, 11:04pm
                   
                  5 
               
             
            
              and as I assume n is my value I want to round ?
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 25, 2007, 11:05pm
                   
                  6 
               
             
            
              On 9/16/07, kendear [email protected] 
So the question is how to round up some value to two decimal points?
 
one way is to use   round(n * 100) / 100.0
 
in Ruby, it is like   (n * 100).round / 100.0
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 25, 2007, 11:05pm
                   
                  7 
               
             
            
              
n = 12.3456
 
So clear , so easy.
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 25, 2007, 11:10pm
                   
                  8 
               
             
            
              sorry, line 3 should be n.round()
             
            
              
            
                
           
          
            
              
                pgega  
              
                  
                    September 25, 2007, 11:10pm
                   
                  9 
               
             
            
              Thanks,
And which part of the code corresponds for the number of decimal