Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Deal with floating-point numbers in WRT environment

From Wiki
Jump to: navigation, search
Article Metadata
Device(s): WRT 1.0
Created: vphong (03 Dec 2007)
Last edited: hamishwillee (10 Oct 2012)


The format of a floating-point number is system language dependent. That is in some languages the radix point symbol is a dot "." and in some languages the radix point symbol is a comma ",". However, the JavaScript engine in WRT never recognizes a comma "," as a radix point of a floating-point number. It does not neither recognize a dot "." as a radix point of a floating-point number if the current system language uses a comma "," as the radix point symbol. Therefore, a defined floating-point number with a dot "." separating the integral part from the fractional part of that number will not always be recognized as a floating-point number. Instead, in those system languages that use a comma as the radix point symbol, the fractional part will be truncated and a floating-point number will become an integer.

E.g. var pi = 3.1416;

  pi is 3 in Italian or Finnish system language
  pi is 3.1416 in English system language


To make your codes work in all system languages, use the following solutions to solve the problem:

Solution 1: Let the system create the floating-point number


    var pi = 3 + 1416/10000;
    var d = 5 + 8/10;
    var cir = d * pi;

Solution 2: Define a floating-point number as a string, then use the parseFloat() method to convert it to a floating-point number


    var pi = "3.1416";
    var d = "5.8";
    var cir = parseFloat(d) * parseFloat(pi);
This page was last modified on 10 October 2012, at 05:12.
38 page views in the last 30 days.