For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Functions l / 

LSNumberFormat

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Description

Formats a number in a locale-specific format.

Returns

A formatted number.

  • If no mask is specified, it returns the number formatted as an integer
  • If no mask is specified, truncates the decimal part; for example, it truncates 34.57 to 35
  • If the specified mask cannot correctly mask a number, it returns the number unchanged
  • If the parameter value is "" (an empty string), it returns 0.

Category

Display and formatting functions, International functions

Function syntax

LSNumberFormat(number [, mask, locale])

See also

GetLocale, SetLocale; Handling data in ColdFusion in the Developing ColdFusion Applications

History

ColdFusion 8: Added the locale parameter.

ColdFusion MX:

  • Changed behavior: if the specified mask format cannot correctly mask a number, this function returns the number unchanged. (In earlier releases, it truncated the number or threw an error.) (If no mask is specified, ColdFusion MX truncates the decimal part as ColdFusion 5 does. For example, it truncates 1234.567 to 1235.)
  • Changed formatting behavior: this function might return different formatting than in earlier releases. This function uses Java standard locale formatting rules on all platforms.

Parameters

Parameter

Description

number

Number to format

mask

LSNumberFormat mask characters apply, except: dollar sign, comma, and dot are mapped to their locale-specific equivalents.

locale

Locale to use instead of the locale of the page when processing the function

The following table lists the LSNumberFormat mask characters:

Character

Meaning

_

(Underscore.) Digit placeholder.

9

Digit placeholder. (Shows decimal places more clearly than _ .)

.

Location of a mandatory decimal point (or locale-appropriate symbol).

0

Located to the left or right of a mandatory decimal point. Pads with zeros.

( )

If number is less than zero, puts parentheses around the mask.

+

Puts plus sign before positive number; minus sign before negative number.

-

Puts space before positive number; minus sign before negative number.

,

Separates every third decimal place with a comma (or locale-appropriate symbol).

L,C

Left-justifies or center-justifies number within width of mask column. First character of mask must be L or C. The default value is right-justified.

$

Puts a dollar sign (or locale-appropriate symbol) before formatted number. First character of mask must be the dollar sign ($).

^

Separates left and right formatting.

Note:

If you do not specify a sign for the mask, positive and negative numbers do not align in columns. To put a plus sign or space before positive numbers and a minus sign before negative numbers, use the plus or hyphen mask character, respectively.

Usage

This function uses Java standard locale formatting rules on all platforms. The position of symbols in format masks determines where the codes take effect. For example, if you put a dollar sign at the far left of a format mask, ColdFusion displays a dollar sign at the left edge of the formatted number. If you separate the dollar sign on the left edge of the format mask by at least one underscore, ColdFusion displays the dollar sign just to the left of the digits in the formatted number. These examples show how symbols determine formats:

Number

Mask

Result

4.37

$___._

"$ 4.37"

4.37

$_._

" $4.37"

The positioning can also show where to put a minus sign for negative numbers:

Number

Mask

Result

-4.37

-___._

"- 4.37"

-4.37

-_._

" -4.37"

The positions for a symbol are: far left, near left, near right, and far right. The left and right positions are determined by the side of the decimal point on which the code character is shown. For formats that do not have a fixed number of decimal places, you can use a caret (^) to separate the left fields from the right.An underscore determines whether the code is placed in the far or near position. Most code characters effect is determined by the field in which they are located. This example shows how to specify where to put parentheses to display negative numbers:

Number

Mask

Result

3.21

C(_^_)

"( 3.21 )"

3.21

C_(^_)

" (3.21 )"

3.21

C(_^)_

"( 3.21) "

3.21

C_(^)_

" (3.21) "

To set the default display format of date, time, number, and currency values, use the SetLocale function. When converting from string to double, to prevent rounding errors, this function adds a rounding factor of 1.5543122344752E-014 to the converted number. For example, without adding the rounding factor, converting the string value 1.275 to double with two digits of precision results in a value of 1.27499999999999999, which would be rounded up to 1.27. By adding the rounding factor, the conversion correctly results in a value of 1.28. If you round off a double, such as 1.99499999999999999999999999999, where the last decimal is 10E-14, the rounding factor can cause an incorrect result.

Example

<h3>LSNumberFormat Example</h3> 
<p>LSNumberFormat returns a number value using the locale convention. 
<!--- loop through a list of locales and show number values ---> 
<cfloop LIST = "#Server.Coldfusion.SupportedLocales#" 
index = "locale" delimiters = ","> 
<cfset oldlocale = SetLocale(locale)> 
<cfoutput><p><b><i>#locale#</i></b><br> 
#LSNumberFormat(-1234.5678, "_________")#<br> 
#LSNumberFormat(-1234.5678, "_________.___")#<br> 
#LSNumberFormat(1234.5678, "_________")#<br> 
#LSNumberFormat(1234.5678, "_________.___")#<br> 
#LSNumberFormat(1234.5678, "$_(_________.___)")#<br> 
#LSNumberFormat(-1234.5678, "$_(_________.___)")#<br> 
#LSNumberFormat(1234.5678, "+_________.___")#<br> 
#LSNumberFormat(1234.5678, "-_________.___")#<br> 
</cfoutput> 
</cfloop>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices