473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Removing decimal points

40
I'm wondering which data type will only give me the whole number and drop off the rest of the fraction?

For example if I have 3.14, but I just want 3, how can i get this done?
Sep 10 '08 #1

✓ answered by chaarmann

Convert the floating point number to an int.
int result = (int) 3.14;

You could also do it with Math.floor() or Math.ceil() or Math.round() or especially Math.rint(), depending in which way you want to cut off.

3 15725
pronerd
392 Expert 256MB
There are a number of API options for controlling output formatting. This will show you what you want.

http://java.sun.com/docs/books/tutor...malFormat.html
Sep 10 '08 #2
chaarmann
785 Expert 512MB
Convert the floating point number to an int.
int result = (int) 3.14;

You could also do it with Math.floor() or Math.ceil() or Math.round() or especially Math.rint(), depending in which way you want to cut off.
Sep 11 '08 #3
samido
52
some titorials:

{
double d = 3.43;
int x ;
double s;
s = x; // right
x = s; // wrong
x = (int)d; //write
x = d; // wrong
. // ???
. // ???
. // ???

}

Sam Rabophala
Sep 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Enno Middelberg | last post by:
Hi, I'm sure someone asked this question before, but I can't find the solution on the web or in the groups. I want to print out columns of numbers which are aligned at the decimal point,...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
7
by: hana1 | last post by:
Hello experts, I used to program in C/C++ and now switched to Java. I am having a difficulty that I need your help with. How can I limit a double variable to hold 2 decimal points only? Say I...
15
by: Kay Schluehr | last post by:
I wonder why this expression works: >>> decimal.Decimal("5.5")**1024 Decimal("1.353299876254915295189966576E+758") but this one causes an error 5.5**1024 Traceback (most recent call...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
0
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money...
1
by: ianhen | last post by:
Hi I have a Web Form which I need to get results shown to 2 decimal points only. In the Head I have: - function heatoutput() { var vWidth=document.heatcalculator.roomwidth.value; var...
13
by: Mumia W. | last post by:
Hello all. I have a C++ program that can count the YOYOs that are in a grid of Y's and O's. For example, this Y O Y O O Y O Y O Y O O Y O Y Y O Y O Y O O Y O O Y Y O Y O
0
by: apple27 | last post by:
Hi, Appreciate your guys help.. Im a newbie in OWC.Trying to search for OWC objects to complete a few charts. Still having difficulty on this :- My questions: 1. I need to come out with a...
13
by: Eps | last post by:
Hi there, I believe all strings in .net are unicode by default, I am looking for a way to remove all non ascii characters from a string (or optionally replace them). There is an article on...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.