Reputation: 37
My string contains floating numbers with positive and negative sign and character. Basically complex numbers. I have to separate them first from string then further as real and imaginary, keeping in mind that sign should remain along the number.
Currently, I am using Split to get them separated as sub strings but further in separating real and imaginary I get error reading negative sign. Need help.
this is my string "-0.6026630828112783-0.6026630828112783 i+0.012343244232-0.90293888321i..."
I use String.split("[\Q+-\Ei]"); and i get -0.6026630828112783-0.6026630828112783i (1st number). i further want to separate real and imaginary along with sign
Upvotes: 0
Views: 106
Reputation: 1013
Use Below Code to Convert String
to int
:)
Integer.parseInt("" + Math.round(Float.parseFloat("-12.233")))
For Split numbers, First Add Separator Char before +
and -
. Like ,
.
Then Split by Separator Char.
Upvotes: 2