5,593,293 Members 32,686 Now Online
XDA Developers Android and Mobile Development Forum

Decimal to int

Tip us?
 
cdbaugher
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 2
Join Date: Dec 2013
Default Decimal to int

I'm try to create a app to track my reps sales but I can't figure out how to get int to use 0.0

example

int points;
points = 0;

This works but how would I get it to register 0.0 instead 0

Thanks for your help. I'm still kinda new at this.
 
nikwen
Old
#2  
nikwen's Avatar
Recognized Contributor
Thanks Meter 1230
Posts: 2,607
Join Date: Feb 2013
What's about this?

Code:
int points;
points = (int) 0.0;
This will cut off all decimals. If you want to have the decimals, use double instead of int.
 
PicomatStudios
Old
#3  
Member
Thanks Meter 18
Posts: 76
Join Date: Sep 2012
Quote:
Originally Posted by cdbaugher View Post
I'm try to create a app to track my reps sales but I can't figure out how to get int to use 0.0

example

int points;
points = 0;

This works but how would I get it to register 0.0 instead 0

Thanks for your help. I'm still kinda new at this.

An int is an integer (so, no fractional part)
For a floating point number, you'll need something else.

float is one option
Code:
float points = 0.0f;
This may be worth reading.
 
vishjoshi
Old
#4  
vishjoshi's Avatar
Junior Member
Thanks Meter 1
Posts: 13
Join Date: Sep 2013
Location: Junagadh
Quote:
Originally Posted by cdbaugher View Post
I'm try to create a app to track my reps sales but I can't figure out how to get int to use 0.0

example

int points;
points = 0;

This works but how would I get it to register 0.0 instead 0

Thanks for your help. I'm still kinda new at this.
Use Double, it can store the decimal values in it. Int cannot store the decimal values.
 
coolbud012
Old
#5  
coolbud012's Avatar
Senior Member
Thanks Meter 23
Posts: 194
Join Date: Sep 2012
Location: Bangalore
use double instead of float...that will give you 0.0 instead of 0...

Aptitude Cracker - An Application for all Competitive Exams and all In One Aptitude Preparation
---------------------------------------------------------------------------------------------------------------------------------
DroidAcid - Get all android tutorials and Micromax CanvasHD A116 guides.
 
PicomatStudios
Old
#6  
Member
Thanks Meter 18
Posts: 76
Join Date: Sep 2012
Quote:
Originally Posted by coolbud012 View Post
use double instead of float...that will give you 0.0 instead of 0...
double and float are both floating point representations (64 bit vs 32 bit)
 
EmptinessFiller
Old
#7  
Member
Thanks Meter 21
Posts: 88
Join Date: Sep 2013
I say 0 is exactly the same like 0.0
But you can change the look when turn it to string:
String.format(...)

Regards
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Prevent Unwanted Butt Dialing with Smart Pocket Guard

You may recall that back in August of last year, we took a look atAir SwiperbyXDA … more

Google ATAP Details Project Ara in Developers’ Conference

Earlier today, the Google ATAP teamkicked offits first ever Project Ara … more

HTC Sense 6 Ported to the Nexus 5

The Google Nexus 5 is regarded as having everything an Android user needs or wants: timely updates, … more