BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-20-2009, 10:46 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 9530
PIN: N/A
Carrier: Telus
Posts: 107
Post Thanks: 0
Thanked 0 Times in 0 Posts
Question Divide By 100 - JDE 4.7

Please Login to Remove!

Hello Everyone

I am dividing a int by 100 and storing the result in float. The result I get is 0.0

int abc = 15;
float xyz = 15/100;

the result is 0.0.

What am I doing wrong?

Thanks
Offline  
Old 03-20-2009, 11:10 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

(int) 15 / 100 = 0.15

This result is then truncated when forced into an int (intermediate) value, so it becomes zero.

Try this:

float xyz = 15.0 / 100.0;

Last edited by Dougsg38p : 03-20-2009 at 11:12 AM.
Offline  
Old 03-20-2009, 11:33 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2009
Model: 9530
PIN: N/A
Carrier: Telus
Posts: 107
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

It worked.

Thanks Dougsg38p.
Offline  
Old 03-23-2009, 12:03 AM   #4 (permalink)
Knows Where the Search Button Is
 
baskaraninfo's Avatar
 
Join Date: Feb 2009
Location: Bangalore
Model: 9350
PIN: N/A
Carrier: Telstra
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

float xyz = (float) 15/100;

You can even try this DD12
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

MICRO MEMORY CARD 8MB; NO BATTERY REQ, 6ES7953-8LP31-0AA0
$452.8
MICRO MEMORY CARD 8MB; NO BATTERY REQ,  6ES7953-8LP31-0AA0 picture1pc Honeywell Memory Module 620-0027 xhg04
$1000.01
1pc Honeywell Memory Module 620-0027 xhg04 pictureOSTR-KCW778-Work Smart Ergonomically Designed Knee Chair with Casters, Memory F
$109.07
OSTR-KCW778-Work Smart Ergonomically Designed Knee Chair with Casters, Memory F pictureMemory Foam Seat and Back Cushion
$24.98
Memory Foam Seat and Back Cushion picture55893-1103 Radiant System AVE6432U36A3133E4-A P1510 Samsung RAM Memory Avant
$1.99
55893-1103 Radiant System AVE6432U36A3133E4-A P1510 Samsung RAM Memory Avant picture






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