LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-13-2006, 02:14 PM   #1
vdogvictor
Member
 
Registered: Feb 2004
Distribution: Arch
Posts: 498

Rep: Reputation: 31
Parse decimal string into an int in Java


Hi, Let me thank you for your time first off. I have what most of you will probably consider a simple question.

I am using a JOptionPane.showInputDialog to prompt the user to enter a number and then parsing an int from that string. How can I, if the user enters a decimal number, round it to the nearest integer number and parse it to an int. Thanks again.
 
Old 10-13-2006, 05:19 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Try that:
Code:
Math.round(Double.parseDouble(string))
 
Old 10-13-2006, 06:34 PM   #3
vdogvictor
Member
 
Registered: Feb 2004
Distribution: Arch
Posts: 498

Original Poster
Rep: Reputation: 31
Thanks, that worked perfectly.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
converting a int to string irfanhab Programming 6 07-30-2005 09:40 PM
C++ std::string to int Slaxx Programming 1 10-30-2004 10:03 PM
int to string+sendto pantera Programming 3 08-19-2004 07:19 PM
string to int BadTaste Programming 11 08-18-2004 10:23 AM
string to int in C h/w Programming 2 12-05-2003 03:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration