我需要在我正在构建的当前应用中显示当前的海拔高度。但是,确定海拔高度后,标签将显示为xxx.xxxxxxxxxxxx 它在小数点的另一侧超级远。我只希望它在小数点的另一侧最多给出2个数字。这怎么可能?
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations [0]
self.speedLabel.text = String(location.speed)
self.altitudeLabel.text = String(location.altitude)
CLGeocoder().reverseGeocodeLocation(location) { (placemarks, error) in
if error != nil {
print(error!)
}
这是我目前的代码。
就像我说的那样,我只想将海拔高度显示为" XX.XX"而不是XX.XXXXXXXXX
答案 0 :(得分:0)
试试这个:
SET SERVEROUTPUT ON
DECLARE
email_body CLOB;
BEGIN
email_body:=to_clob('Hel's Message');
DBMS_OUTPUT.PUT_LINE(length(email_body));
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUt_LINE(SQLCODE||' '||SQLERRM);
END;
self.altitudeLabel.text = location.altitude.decimal(places:2)
答案 1 :(得分:-2)
试试吧:
self.altitudeLabel.text = String(format: "%.2f", location.altitude)