Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8195459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:08:44+00:00 2026-06-07T05:08:44+00:00

I need to store the 2 places after decimal (currency amount, so need only

  • 0

I need to store the 2 places after decimal (currency amount, so need only upto 2 places) in an XSL variable before I do a ceil function.

<xsl:element name="BaseFare"><xsl:value-of select="ceiling(BaseAmount/Amount * (1 - ($promoDisc div 100)))"/></xsl:element>

For eg. if the result of the Amount is 499 and promoDisc = 8%, then the discounted Amount would be 459.08 – I need to store “08” (with the zero) in a variable for use later, while I return the ceiling amount (460) in the output XML. Thought I could just do a string function and read 2 chars after the decimal into a variable rather than do any math?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:08:46+00:00Added an answer on June 7, 2026 at 5:08 am

    There are different ways to do this extraction:

    I. Using the string representation of the number:

    concat('.',substring(substring-after($x, '.'), 1, 2))
    

    II. Using standard math functions:

    $x - floor($x)
    

    This evaluates to the decimal part of any positive number $x.

    Use one of the functions: format-number(), round(), round-half-to-even() (the last function available only XPath 2.0 / XSLT 2.0) to round it to two decimal places.

    In XSLT 1.0 one way to get from a positive number exactly the digits in the two decimal places after the decimal point (truncate without rounding), is:

    format-number(
                  floor(100* $x) div 100
                 -
                  floor(floor(100* $x) div 100),
                  '.00'
                  )
    

    Here is a complete example of the described methods:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/">
    
       <xsl:value-of select=
       "concat('.',substring(substring-after(0.12543, '.'), 1, 2))"/>
    =========
       <xsl:value-of select=
          "format-number(0.12543, '.00')"/>
    =========
       <xsl:value-of select=
        "format-number(
                       floor(100* 999.12543) div 100
                      -
                       floor(floor(100* 999.12543) div 100),
                       '.00'
                       )
          "/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on any XML document (not used), the result is:

       .12
    =========
       .13
    =========
       .12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store a very large amount of instances of my class, and
I need store just 10 arrays in my app, which I can change from
I have id values for products that I need store. Right now they are
I need to store a login session when the user is login and remove
I need to store GPS coordinates in a database. I've heard that floats are
I need to store user credentials in my app. I can store and retrieve
I need to store locally on android devices some images I get from the
I need to store lotto numbers in a SQL database. There are 8 separate
I need to store a huge number of elements in a std::vector (more that
I need to store a large number of geocoordiantes in a database in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.