Thursday, January 17, 2013

[iOS] Calculation of the discount.

-(void) calculation
{
    
    float priceField = [PriceDecimal.text floatValue];
    float taxField = [RateDecimal.text floatValue];
    float discField = [DiscDecimal.text floatValue];
    
    if([usingTax isOn])
    {
        
        if([dallarOrPercent selectedSegmentIndex] == 0)
        {
            float price = (priceField * (1 - discField* 0.01 )) * (taxField*0.01+1);
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = priceField * (discField *0.01)+ ((priceField * (discField *0.01))*(taxField*0.01));
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
        else
        {
            float price = (priceField -  discField) * (taxField*0.01+1);
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = discField *(1+taxField*0.01);
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
    }
    else
    {
        if([dallarOrPercent selectedSegmentIndex] == 0)
        {
            float price = (priceField * (1 - discField* 0.01));
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = priceField * (discField *0.01);
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
        else
        {
            float price = priceField - discField;
            finalValueLabel.text = [NSString stringWithFormat:@"%.2f", price];
            float discValue = discField;
            DiscLabel.text = [NSString stringWithFormat:@"%.2f", discValue];
        }
    }
}

No comments: