/** * Parses a string to produce a {@link Complex} object. * * @param source the string to parse. * @return the parsed {@link Complex} object. * @throws MathParseException if the beginning of the specified string * cannot be parsed. */ public Complex parse(String source) throws MathParseException { ParsePosition parsePosition = new ParsePosition(0); Complex result = parse(source, parsePosition); if (parsePosition.getIndex() == 0) { throw new MathParseException(source, parsePosition.getErrorIndex(), Complex.class); } return result; }
NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(2); nf.setMaximumFractionDigits(2); ComplexFormat cf = new ComplexFormat(nf); Complex complex = cf.parse("29.90000");
ComplexFormat cf = new ComplexFormat(); Complex c = cf.parse("1.110 + 2.222i");
ComplexFormat cf = new ComplexFormat(); Complex c = cf.parse("1.110 + 2.222i");
/** * Parses a string to produce a {@link Complex} object. * * @param source the string to parse. * @return the parsed {@link Complex} object. * @throws MathParseException if the beginning of the specified string * cannot be parsed. */ public Complex parse(String source) throws MathParseException { ParsePosition parsePosition = new ParsePosition(0); Complex result = parse(source, parsePosition); if (parsePosition.getIndex() == 0) { throw new MathParseException(source, parsePosition.getErrorIndex(), Complex.class); } return result; }
studentAnswerComplex = complexFormat.parse(trimmedValue);
studentAnswerComplex = complexFormat.parse(trimmedValue);
answerComplex = complexFormat.parse(answer); } catch(MathParseException ex) { log.debug("Number is not Complex: " + answer);
answerComplex = complexFormat.parse(answer); } catch(MathParseException ex) { log.debug("Number is not Complex: " + answer);
ComplexFormat cf = new ComplexFormat(); Complex c = cf.parse("1.110 + 2.222i"); Complex second = new Complex(2.0, 5.0); Complex answer = c.log(); // natural logarithm. answer = c.cos(); // cosine answer = c.pow(second); // first raised to the power of second ComplexFormat format = new ComplexFormat(); // default format String s1 = format.format(c); // s1 contains "1.110 + 2.222i" String s2 = format.format(second); // s2 contains "2.0 + 5.0i"