Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

Sum value up to closest whole nr

$
0
0

Hi.

I am trying to do some calculations.

I want to add 3 strings like 1+2+3 and then multiply the answer by 3,5.

But my result is summed up to the closest whole nr down. I want it to be summed up instead.

For ex. 1+2+3 = 6 X 3,5 = 21 So thats ok.

But if i change it to 2+2+3 = 7 X 3,5 = 24,5

Then it sums it up to 24 and i want it to be summed up to 25.

Here is how i sum things up.

I get the rows from a sqlite DB and the fields are all whole nrs. No decimals.

var sum = 0;
        var one = rows.getFieldByName('one');
    var two = rows.getFieldByName('two');
    var three = rows.getFieldByName('three');
 
        var q = parseInt(one,10)+parseInt(two,10)+parseInt(three,10);
    sum = sum + q*3.5;
 
    var totalSum = Ti.UI.createLabel({
    bottom  : '58dp',
    left: '15dp',
    text :  'Total Sum: '+sum.toFixed(0)+':-' ,
        font : {
        fontSize : '12dp',
        fontFamily : 'Arial'
    },
    color : '#fff'
});
Any ideas?

Thanx.


Viewing all articles
Browse latest Browse all 7655

Trending Articles