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

Peak DCA55 Atlas Semiconductor Analyser
$82.87
Peak DCA55 Atlas Semiconductor Analyser pictureBuss FWX 250 Semiconductor 250 Amp Fuse
$45.0
Buss FWX 250 Semiconductor 250 Amp Fuse picture8SOIC (150mils) X8 RASCO-Nextest CY22801 HD Board REV. CYPRESS SEMICONDUCTOR
$899.99
8SOIC (150mils) X8 RASCO-Nextest CY22801 HD Board REV. CYPRESS SEMICONDUCTOR pictureBlue-violet Laser Diode Head Engraving Emitter Focusable Semiconductor La... New
$44.99
Blue-violet Laser Diode Head Engraving Emitter Focusable Semiconductor La... New pictureRefrigeration Cooling System Kit Semiconductor Cooler Module w/ Double Fans B9Y3
$24.53
Refrigeration Cooling System Kit Semiconductor Cooler Module w/ Double Fans B9Y3 picture






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