Back to project page android-appwidget-cirrus.
The source code is released under:
MIT License
If you think the Android project android-appwidget-cirrus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* Copyright 2014 Wayne D Grant (www.waynedgrant.com) Licensed under the MIT License */ /* w w w .jav a 2 s. c o m*/ package com.waynedgrant.cirrus.presentation.formatters; import static com.waynedgrant.cirrus.units.RainfallUnit.MILLIMETRES; import java.math.RoundingMode; import java.util.Locale; import com.waynedgrant.cirrus.measures.Rainfall; import com.waynedgrant.cirrus.units.RainfallUnit; public class RainfallFormatter { private Rainfall rainfall; public RainfallFormatter(Rainfall rainfall) { this.rainfall = rainfall; } public String format(RainfallUnit unit) { String formatted = null; if (rainfall != null) { String formatString = null; if (unit == MILLIMETRES) { formatString = "%1.2f mm"; } else { formatString = "%1.2f in"; } formatted = String.format(Locale.US, formatString, rainfall.getValue(unit).setScale(2, RoundingMode.HALF_DOWN)); } else { if (unit == MILLIMETRES) { formatted = "-.-- mm"; } else { formatted = "-.-- in"; } } return formatted; } }