Floating point numbers

Discussion in 'XML' started by John Wilkinson, Oct 28, 2005.

  1. Hi,
    I am creating a table of values. One column is the addition of the other 2
    columns.Both columns are floating point, and may be any value 0-100
    For some values we find that we get a good output from the sum, such
    as,97.67+2.31=99.98, others we get problems: 96.56+0.54=79.100000000001.
    How do I truncate these figures to 2 decimal places?
     
    John Wilkinson, Oct 28, 2005
    #1
    1. Advertising

  2. John Wilkinson wrote:


    > I am creating a table of values. One column is the addition of the other 2
    > columns.Both columns are floating point, and may be any value 0-100
    > For some values we find that we get a good output from the sum, such
    > as,97.67+2.31=99.98, others we get problems: 96.56+0.54=79.100000000001.
    > How do I truncate these figures to 2 decimal places?


    Well what language are you using, as you are posting in an XML group
    XSLT/XPath 1.0 perhaps?
    In XPath 1.0 you have the round function
    <http://www.w3.org/TR/xpath#function-round>
    and in XSLT 1.0 you additionally have the format-number function
    <http://www.w3.org/TR/xslt#format-number>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Oct 28, 2005
    #2
    1. Advertising

  3. On Fri, 28 Oct 2005 16:34:01 +0200, Martin Honnen wrote:

    > www.w3.org/TR/xslt#format-number>


    Thanks Martin,
    It took a while to decipher the syntax of format-number, but I got there in
    the end.
     
    John Wilkinson, Oct 28, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. H aka N
    Replies:
    15
    Views:
    15,691
    Ben Jones
    Mar 2, 2006
  2. Motaz Saad
    Replies:
    7
    Views:
    6,503
  3. Replies:
    4
    Views:
    1,297
    Default User
    Feb 22, 2006
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,356
    Saraswati lakki
    Jan 6, 2012
  5. teeshift
    Replies:
    2
    Views:
    268
    Chris Pearl
    Dec 1, 2006
Loading...

Share This Page