java - stringbuffer and "0&" causes truncation or escaping -


sorry unclear title don't know call it, i'll go ahead , explain what's happening.

i'm using stringbuffer build url. looks this:

http://maps.googleapis.com/maps/api/geocode/json?latlng=49.0516736,8.38891840&sensor=false 

i encountered behavious when comparing string in unit-test actual result of method.

and assertion-error i'm getting:

latlng=49.0516736[,8.38891840]&sensor=false> was:<...on?latlng=49.0516736[,8.3889184]&sensor=false 

the emphasis on character sequence 0]& , 4]& right before sensor=false

if remove 0 before & test goes green.

then created string looks this:

latlng=49.0516736,8.3889184&sensor=false 

so ... expected. it's not problem, 0 gets truncated , test fail - i've proved code doing it's supposed (when remove zero), want know happening here.

0& must kind of indication array-access or kind of escaping. don't know. idea what's causing behaviour?

edit:

here's code i'm using

stringbuffer s = new stringbuffer( grailsapplication.config.geocodingurl.tostring() ) s.append(coordinates.latitude) s.append(",") s.append(coordinates.longitude) s.append("&sensor=false") return s.tostring() 

there formatting/padding issue when converting double string.

what doing using stringbuilder#append(double) in end calls double#tostring().

see javadoc of methods , find out how double values converted string. alternatively, if want have control on code, use numberformat or it's subclasses.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -