Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Operation in String to Double conversion Date: Sun, 14 Oct 2012 20:32:15 +0000 (UTC) Organization: UK Free Software Network Lines: 36 Message-ID: References: <3a63483c-4322-4bfb-8c28-2d528bf48443@googlegroups.com> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1350246735 25808 84.45.235.129 (14 Oct 2012 20:32:15 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Sun, 14 Oct 2012 20:32:15 +0000 (UTC) User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.java.programmer:19333 On Sun, 14 Oct 2012 12:39:18 -0700, William Lopes wrote: > Hi guys! > > So, I have to do a conversion between String and Double object, but my > string is a mathematical operation like "100 + 10". Even when I make a > conversion using NumberFormat.getInstance of "100 + 10", my result is > 100.0 only. > > I would like to do it without split my string of way manually. > Sounds like you need an mathematical expression parser. I don't think there's anything suitable in the standard classes. You can: 1)see if there's a third party mathematical expression parser available 2)use a compiler generator like Coco/R http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ to create one. 3)attempt to roll your own from scratch. If it was my problem I'd work down that list in the order shown unless there are constraints set, i.e. its an assignment that you are required to solve by yourself. I've used Coco/R to generate an equivalent Java class that could handle the sort of expressions used in C preprocessor commands: it was dead easy once I understood how Coco/R works, but then again I had previously solved non-trivial problems with lex and yacc. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |