PowenKo, Android, Tutorial 008-1, String, String format


// 120.456 –>+120456000

//12.3456789–>  +12345679

// 12.3456789 –> -12345679


package com.powenko.Tutorial_String_format;



import android.app.Activity;

import android.os.Bundle;



public class Tutorial_String_formatActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

double geoLongitude =120.456;

double geoLatitude = -12.3456789;

String m_GPSlong=Convert_double_To9String(geoLongitude);

}

// 120.456 -->+120456000

//12.3456789-->  +012345679

// 12.3456789 --> -012345679


   // sample 
    private  String Convert_double_To9String(double i_value)
    {    
    	 double d = i_value /1000;
    	 String m_GPSlong=String.format("%.9f", d);
         m_GPSlong=m_GPSlong.replace("0.", "");
         if(i_value>0){m_GPSlong="+"+m_GPSlong;}
         return m_GPSlong;
    
    }
    

sample code:

Tutorial_String_format


Leave a Reply