Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3002] iOS: Ti.UI.createLabel with text set as value of 0.07 gives 0.07000000000001

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionCannot Reproduce
Resolution Date2017-07-10T21:44:09.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sn/a
ComponentsiOS
Labelsapi
Reporterlordsiris
AssigneeIngo Muschenetz
Created2011-04-15T03:34:27.000+0000
Updated2017-07-10T21:44:09.000+0000

Description

currentValue = 0.07;

            var currentReadingValueLabel = Ti.UI.createLabel({
                text: currentValue,
                left: 110,
                top: 22,
                height: 'auto',
                color: '#fff',
                width: 150,
                textAlign: 'left',
                font:{
                    fontSize: 24,
                    fontStyle: 'bold'
                }
            });

When displayed in both the iphone simulator and on the device (iPhone 3GS, iOS 4.1) I don't get just 0.07 but something like 0.07000000000001. Using Dev 1.2.2 with iOS SDK 4.2 and Titanium Mobile 1.5.1 (latest).

Comments

  1. lordsiris 2011-04-15

    Maybe this is just an issue with javascript decimal fraction precision, but it's not clear since no arithmetic functions are being applied. Worked around the issue with currentValue = currentValue.toString();.

  2. Stephen Tramer 2012-07-26

    Confirmed SDK 2.2.0.014b86f. This is probably a rounding error due to us using 32-bit float instead of 64-bit.
  3. Lee Morris 2017-07-10

    I am unable to reproduce this issue with the following environment; iPhone 6 (10.0) Studio 4.9.0.201705302345 Ti SDK 6.1.1 GA Appc NPM 4.2.9 Appc CLI 6.2.2 Ti CLI 5.0.14 Alloy 1.9.11 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131

JSON Source