Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-15-2009, 05:41 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
Default Total Array as Decimal not Int.

So Im using this code to add all the contents of an array and get a total numerical value out of it. It works really good with one problem... it works with intigers and i need decimals too. If the array has 3.4,1.5, and 7.0 it gives 11 but i need it to give 11.9. Anyone found out how to do this? Do you use doubles? Thanks!

int sum=0;
for(int x=0; x < [mainDelegate.lastcitieslc count]; x++)
{
sum += [[mainDelegate.lastcitieslc objectAtIndex:x] intValue];
}
[mainDelegate.actsections replaceObjectAtIndex:0 withObject:[NSString stringWithFormat:@"%d", sum]];
__________________
Check out our Apps!
Boxen4Oxen
VisCenter

Film Budget

Everwell TV
starwarsdevwookie59 is offline   Reply With Quote
Old 08-16-2009, 12:10 AM   #2 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
Send a message via AIM to kelvinkao
Default

Simple, instead of
int sum
use
float sum

Instead of %d, use %f.

And that's all.
kelvinkao is offline   Reply With Quote
Reply

Bookmarks

Tags
array, total

Thread Tools
Display Modes

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

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



» Advertisements
» Online Users: 237
16 members and 221 guests
@sandris, ADY, dacapo, Dani77, djohnson, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, timle8n1, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:02 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0