commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grzegorz Szpetkowski <gszpetkow...@gmail.com>
Subject [math] ComplexFormat parse for inverted complex number
Date Mon, 11 Oct 2010 20:38:45 GMT
I have a question how can I (easily) parse String like that:

String sZ = "20i + 5.4";

On page http://commons.apache.org/math/userguide/complex.html I found example:

ComplexFormat cf = new ComplexFormat();
Complex c = cf.parse("1.110 + 2.222i");

It's ok, but if I have inverted form like "20i + 5.4" then there is
exception: "org.apache.commons.math.MathRuntimeException$9:
unparseable complex number: "20i + 5.4".

Pseudo-algorithm for proposed solution:
1) Parse first number
2) IF first number has imaginary character THEN remember that second
number should be real number (without imaginary character)
3) Parse second number
4) IF second number has imaginary character and first had it too (look
at 2)), THEN throw exception
Thanks ! Greg

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message