Namespaces

Variants
Actions

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 over the next few weeks. Thanks for all your past and future contributions.

Revision as of 05:12, 10 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Deal with floating-point numbers in WRT environment

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

Description

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


Solution:

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

E.g.

    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

E.g.

    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.
51 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×