summaryrefslogtreecommitdiff
path: root/tools/source/datetime/ttime.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/source/datetime/ttime.cxx')
-rw-r--r--tools/source/datetime/ttime.cxx14
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx
index f1dea02a6afb..7f058cf2ac6d 100644
--- a/tools/source/datetime/ttime.cxx
+++ b/tools/source/datetime/ttime.cxx
@@ -313,10 +313,18 @@ void tools::Time::GetClock( double fTimeInDays,
nSecond = fSeconds;
fSeconds -= nSecond;
- // Do not round the fraction, otherwise .999 would end up as .00 again.
+ assert(fSeconds < 1.0); // or back to the drawing board..
+
if (nFractionDecimals > 0)
- fFractionOfSecond = rtl::math::pow10Exp( std::trunc(
- rtl::math::pow10Exp( fSeconds, nFractionDecimals)), -nFractionDecimals);
+ {
+ // Do not simply round the fraction, otherwise .999 would end up as .00
+ // again. Truncate instead if rounding would round up into an integer
+ // value.
+ fFractionOfSecond = rtl::math::round( fSeconds, nFractionDecimals);
+ if (fFractionOfSecond >= 1.0)
+ fFractionOfSecond = rtl::math::pow10Exp( std::trunc(
+ rtl::math::pow10Exp( fSeconds, nFractionDecimals)), -nFractionDecimals);
+ }
else
fFractionOfSecond = fSeconds;
}