org.apache.struts2.components

## Class Number

- java.lang.Object
- - org.apache.struts2.components.Component
  - - org.apache.struts2.components.ContextBean
    - - org.apache.struts2.components.Number

-     public class Number
      extends ContextBean

  Format Number object in different ways.

  The number tag will allow you to format a Number in a quick and easy way, based on the java.text.NumberFormat class. There are four basic number types, a number, a currency, a percentage and an integer. If a currency is specified, the number format will match the given currency. Further parameters can be overridden as needed.

  If a type is not defined, it will finally fall back to the default NumberFormat.getNumberInstance() formatting.

  Note: If the requested Number object isn't found on the stack, a blank will be returned.

  Configurable attributes are:

  - name
  - currency - you can specify your own currency or as an OGNL expression
  - type - if not specified try to find base on struts.number.format property
  - groupingUsed - see NumberFormat.isGroupingUsed
  - maximumFractionDigits - see NumberFormat.setMaximumFractionDigits
  - maximumIntegerDigits - see NumberFormat.setMaximumIntegerDigits
  - minimumFractionDigits - see NumberFormat.setMinimumFractionDigits
  - minimumIntegerDigits - see NumberFormat.setMinimumIntegerDigits
  - parseIntegerOnly - see NumberFormat.isParseIntegerOnly
  - roundingMode - see below

  Possible values for rounding mode are:

  - ceiling
  - down
  - floor
  - half-down
  - half-even
  - half-up
  - unnecessary
  - up

  Examples

        <!-- START SNIPPET: example -->
        <s:number name="invoice.total" type="currency" currency="XYZ" />
        <s:number name="invoice.quantity" type="number" />
        <s:number name="invoice.discount" type="percentage" />
        <s:number name="invoice.terms" type="integer" />
        <!-- END SNIPPET: example -->

  `Number`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `NUMBERTAG_PROPERTY` Property name to fall back when no format is specified

    - ### Fields inherited from class org.apache.struts2.components.ContextBean

      `var`

    - ### Fields inherited from class org.apache.struts2.components.Component

      `actionMapper, COMPONENT_STACK, devMode, escapeHtmlBody, parameters, performClearTagStateForTagPoolingServers, stack, standardAttributesMap, throwExceptionOnELFailure`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Number(ValueStack stack)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `end(Writer writer, String body)` Callback for the end tag of this component.
    `String` | `getCurrency()`
    `Integer` | `getMaximumFractionDigits()`
    `Integer` | `getMaximumIntegerDigits()`
    `Integer` | `getMinimumFractionDigits()`
    `Integer` | `getMinimumIntegerDigits()`
    `String` | `getName()`
    `String` | `getRoundingMode()`
    `String` | `getType()`
    `Boolean` | `isGroupingUsed()`
    `Boolean` | `isParseIntegerOnly()`
    `void` | `setCurrency(String currency)`
    `void` | `setGroupingUsed(Boolean groupingUsed)`
    `void` | `setMaximumFractionDigits(Integer maximumFractionDigits)`
    `void` | `setMaximumIntegerDigits(Integer maximumIntegerDigits)`
    `void` | `setMinimumFractionDigits(Integer minimumFractionDigits)`
    `void` | `setMinimumIntegerDigits(Integer minimumIntegerDigits)`
    `void` | `setName(String name)`
    `void` | `setParseIntegerOnly(Boolean parseIntegerOnly)`
    `void` | `setRoundingMode(String roundingMode)`
    `void` | `setType(String type)`

    - ### Methods inherited from class org.apache.struts2.components.ContextBean

      `getVar, putInContext, setVar`

    - ### Methods inherited from class org.apache.struts2.components.Component

      `addAllParameters, addParameter, completeExpression, copyParams, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getComponentStack, getParameters, getPerformClearTagStateForTagPoolingServers, getStack, getStandardAttributes, isAcceptableExpression, isValidTagAttribute, popComponentStack, setActionMapper, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, start, stripExpression, toString, usesBody`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### NUMBERTAG_PROPERTY

          public static final String NUMBERTAG_PROPERTY

      Property name to fall back when no format is specified
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Number

          public Number(ValueStack stack)

  - ### Method Detail

    - #### end

          public boolean end(Writer writer,
                             String body)

      Description copied from class: `Component`
      Callback for the end tag of this component. Should the body be evaluated again?
      NOTE: will pop component stack.
      Overrides:
        `end` in class `Component`
      Parameters:
        `writer` - the output writer.
        `body` - the rendered body.
      Returns:
        true if the body should be evaluated again

    - #### setType

          public void setType(String type)

    - #### setCurrency

          public void setCurrency(String currency)

    - #### getName

          public String getName()

      Returns:
        Returns the name.

    - #### setName

          public void setName(String name)

    - #### getType

          public String getType()

      Returns:
        Returns the format.

    - #### getCurrency

          public String getCurrency()

      Returns:
        Returns the currency.

    - #### setGroupingUsed

          public void setGroupingUsed(Boolean groupingUsed)

    - #### isGroupingUsed

          public Boolean isGroupingUsed()

      Returns:
        Returns the grouping used.

    - #### getMaximumFractionDigits

          public Integer getMaximumFractionDigits()

      Returns:
        the maximumFractionDigits

    - #### setMaximumFractionDigits

          public void setMaximumFractionDigits(Integer maximumFractionDigits)

      Parameters:
        `maximumFractionDigits` - the maximumFractionDigits to set

    - #### getMaximumIntegerDigits

          public Integer getMaximumIntegerDigits()

      Returns:
        the maximumIntegerDigits

    - #### setMaximumIntegerDigits

          public void setMaximumIntegerDigits(Integer maximumIntegerDigits)

      Parameters:
        `maximumIntegerDigits` - the maximumIntegerDigits to set

    - #### getMinimumFractionDigits

          public Integer getMinimumFractionDigits()

      Returns:
        the minimumFractionDigits

    - #### setMinimumFractionDigits

          public void setMinimumFractionDigits(Integer minimumFractionDigits)

      Parameters:
        `minimumFractionDigits` - the minimumFractionDigits to set

    - #### getMinimumIntegerDigits

          public Integer getMinimumIntegerDigits()

      Returns:
        the minimumIntegerDigits

    - #### setMinimumIntegerDigits

          public void setMinimumIntegerDigits(Integer minimumIntegerDigits)

      Parameters:
        `minimumIntegerDigits` - the minimumIntegerDigits to set

    - #### isParseIntegerOnly

          public Boolean isParseIntegerOnly()

      Returns:
        the parseIntegerOnly

    - #### setParseIntegerOnly

          public void setParseIntegerOnly(Boolean parseIntegerOnly)

      Parameters:
        `parseIntegerOnly` - the parseIntegerOnly to set

    - #### getRoundingMode

          public String getRoundingMode()

      Returns:
        the roundingMode

    - #### setRoundingMode

          public void setRoundingMode(String roundingMode)

      Parameters:
        `roundingMode` - the roundingMode to set

Copyright © 2000–2023 Apache Software Foundation. All rights reserved.