Display a number with commas

Here's a way to display a number with commas. See attached
code.
I had searched here for help on how to do it, and couldn't
find anything. So, then I wrote this. I'm a hack, self-taught
coder, so there may be a more eloquent way, but this does
work.

Nice, I'm always happy to be humbled.
One more point. If you're going ot use a return statement I
like to keep it
at the very end of the function. So, in a conditional
statement, setting a
local variable to the value to be returned allows you to
return that local
variable and always keep the return statement as the last
line. It just
saves a little searching around for returns in longer
functions. Just a
style choice not necessarily better.
Craig Wollman
Word of Mouth Productions
phone 212 928 9581
fax 212 928 9582
159-00 Riverside Drive West #5H-70
NY, NY 10032
www.wordofmouthpros.com
"duckets" <[email protected]> wrote in
message
news:[email protected]...
>
quote:
Originally posted by:
FasterPastor
> I had searched here for help on how to do it, and
couldn't find
> anything.
>
> You should have asked! here's one I have had sitting
around for a while.
> (code
> attached below). It handles lots of cases which the
other handlers posted
> so
> far do not. Specifically:
>
> Negative numbers - input: -123456
> - craig's: -,123,456
> - dougs's: -,123,456
> - mikes's: -,123,456
> - duck's: -123,456
>
> Floating point numbers - input: pi
> - craig's: 3
> - dougs's: 3
> - mikes's: 3.1,416
> - duck's: 3.1416
>
> Numbers larger than the maxinteger - input: 149668992000
> - craig's: -,654,863,360
> - dougs's: -,654,863,360
> - mikes's: 14,966,899,200,0.0,000
> - duck's: 149,668,992,000
>
> Negative floats - input: -123456.7890
> - craig's: -,123,457
> - dougs's: -,123,457
> - mikes's: -12,345,6.7,890
> - duck's: -123,456.789
>
> Floats larger than the maxinteger - input:
2233445566.7788
> - craig's: -2,061,521,729
> - dougs's: -2,061,521,729
> - mikes's: 223,344,556,6.7,788
> - duck's: 2,233,445,566.7788
>
> Yes.. the code is longer, but if you want to print
something like the
> distance
> in meters to the sun, you need to handle floats
properly!
>
> enjoy ;-)
>
> - Ben
>
>
>
> on stringNumber n
>
> outputString = ""
> inputString = string(n)
>
> if inputString.char[1] = "-" then
> negative = true
> delete inputString.char[1]
> else
> negative = false
> end if
>
> fraction = ""
>
> if inputString contains "e" then
>
> mantissa = inputString.char[1..(offset("e",
inputString)-1)]
> exponent = value(inputString.char[(offset("e",
> inputString)+1)..inputString.length])
>
> decimalChar = mantissa.char[2]
> mantissa = mantissa.char[1] &
mantissa.char[3..mantissa.length]
>
> if mantissa.length < exponent+1 then
> plainNumber = mantissa
> repeat while plainNumber.length < exponent+1
> put "0" after plainNumber
> end repeat
> else
> plainNumber = mantissa.char[1..(exponent+1)]
> fraction = mantissa.char[(exponent+2)..mantissa.length]
> end if
>
> else
>
> if offset(".", inputString)>0 then
> decimalChar = "."
> end if
> if offset(",", inputString)>0 then
> decimalChar = ","
> end if
>
> if offset(decimalChar, inputString)>0 then
> plainNumber = inputString.char[1..(offset(decimalChar,
> inputString)-1)]
> fraction = inputString.char[(offset(decimalChar,
> inputString)+1)..inputString.length]
> else
> plainNumber = inputString
> fraction = ""
> decimalChar = string(1.2).char[2]
> end if
>
> end if
>
> if decimalChar = "." then
> separatorChar = ","
> else
> separatorChar = "."
> end if
>
>
> repeat while plainNumber.char[1] = "0"
> delete plainNumber.char[1]
> end repeat
>
>
> repeat while plainNumber.length > 0
> if plainNumber.length > 3 then
> nextDigits =
>
separatorChar&plainNumber.char[plainNumber.length-2..plainNumber.length]
> delete
plainNumber.char[plainNumber.length-2..plainNumber.length]
> else
> nextDigits = plainNumber
> plainNumber = ""
> end if
> put nextDigits before outputString
> end repeat
>
> repeat while fraction.char[fraction.length] = "0"
> delete fraction.char[fraction.length]
> end repeat
>
> if fraction.length > 0 then
> put decimalChar&fraction after outputString
> end if
>
>
> if negative then
> put "-" before outputString
> end if
>
> return outputString
>
> end
>

Similar Messages

  • Displaying a number with commas in gid

    Hi EveryOne,
                       This is Ram Prasad.I want to display a number with commas in the grid (eg:1,000).In the grid it is shown as 1000.I wan to add commas for this number to be shown in the grid display template.Can any one help on this.

    That's an odd format, so I assume you mean 1 million to be displayed as:  1,000,000 ?
    http://help.sap.com/saphelp_xmii115/helpdata/en/Applet_Reference_Details/ParameterReference.htm#Number Formatting
    #,##0 should provide you with a comma as the thousands separator for all numbers in this column of your iGrid.

  • Display material Number with Serialization Number

    Hi,
    I have a materai with serialization and spilt valuation.
    If i wish to display particular material number with serial numbers under oner valuation type, which T code I need to use?
    Suppose under one valuation type C1 there are 10 materials, numbered with serial numbers, E.g. Material P1 with serial numbers 1 to 10 under Valuation type C1.
    I wish to display this list of serial numbers under that valuation type.
    Thnaks & Regards,
    Kedar

    Check IQ 09
    <i><b>U have to develop report for the details u want</i>
    Material -env.sr no -. Check

  • How to display the number with negative sign in the front in ALV.

    most important, this ALV is also can totalize.
    can someone give me some suggestion?
    thanks   
       jisuwen

    i hope you want a negative sign before a char but holding some number. then that case
    loop at itab.
    concatenate itab-char '-' into itab-char.
    modify itab.
    endloop.
    and you can display in ALV with negative sign...
    Totalling you need to Specify
    DO_SUM = 'X' while populating fieldcatalog...
    If subtotals then you have to Build sort table and based on that you can proceed./.
    examples are there you can find inn SLIS package..
    vijay.

  • Display Row Number with JTable

    Hi everybody,
    I try to build a spreadsheet with Java and Swing. I use Jdk1.2.2 and I looking for display the row Number on the left (Excel - like). I can't fiugre out how to implement this.
    Anyone can give me some help?
    Bye
    Mirko

    Hi Sciak!
    This is what you are looking for ('Row Header' sample, including source code):
    http://www2.gol.com/users/tame/swing/examples/JTableExamples1.html
    Home page:
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    CU,
    Jan

  • PO is fully received but its still displayed in CJI5 with commit = 0

    I have a Material PO with 2 line items fully received (Good Receipt). The PO Line Items Total Amounts and Quantities are correctly shown in CJI3 (Actual Cost). However, the PO Line Items are still shown in CJI5 with Outstanding Commitment Amount = 0. There are only 2 line items in the PO and both of them have been fully received.
    Can anyone give me an explanation why the PO Line Items have not dissapeard in CJI5 and they are still shown in CJI5 with Outstanding Commitment Amount = 0?
    Thanks in advance for your help.
    Marco

    I want to include additional comments in regard to this issue. Initially, I thought I was only missing to check the box "Only Open Items" right at the beginning of transaction CJI5.
    However, I just realized that fully received POs (with GR and IR) are correctly shown in CJI3 (Actual Cost) but are still displayed in CJI5 (Commitments).
    I finally found the problem:
    The user created a Purchase Requisition for an Outline Agreement (Document Type "RV"). The Outline Agreement has been fully consumed by 4 different Purchase Orders. All 4 Purchase Orders has been Received and Invoiced. However, the commitment amount (for the full OA Amount) is still shown in Commitment (CJI5).
    Is this a configuration issue? I would hate to ask my client to delete all PRs with document type "RV" where the OA has been fully consumed (all Outline Agreement POs have GR and IR).
    Any comments or orientation will be appreciated.
    Regards,
    Marco

  • Output number with comma separator

    I have the value 1250 as an amount in a smartform.  And I want to output this as 1,250.  How do I do this?

    Hi...
    Use this function module.....
    it will satify your requirements...
    pass that changing parameter to the smartform..
    DATA: v_cur like TCURX-CURRKEY,
            c_cur(10) type c VALUE '1250'..
      CALL FUNCTION 'SD_CONVERT_CURRENCY_FORMAT'
        EXPORTING
          i_currency                  = v_cur
    *   IMPORTING
    *     E_CURRENCY_INT_FORMAT       =
        changing
          c_currency_ext_format       = c_cur
       EXCEPTIONS
         WRONG_FORMAT                = 1
         OTHERS                      = 2
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      WRITE: C_CUR.
    I believe this will greatly help you.
    Thanks and regards
    Bhuvana

  • Displaying Amount value with comma separation

    Hi ,
    There are some amount fields in the page
    displaying in the format Amount 1000000.00
    Required to display in the format 1,000,000.00
    Is there any profile to set like this or we have to do anything by personalization.
    Regards,
    Krishna.

    Hello Krishna,
    Were you ever successful in finding a fix for this? We have a similar requirement, but I'm not seeing anything where this can be done, either via personalizations or the Property Inspector in java.
    One question I do have though, is if we do turn this on for our number values, and we have an Export to Excel function, is that going to cause the data to get improperly separated when the Export to Excel function is invoked?
    Thanks,
    Janel

  • Separate number with comma

    hi all,
    i want to format 12345678.09 to 12,345,678.09 in jsp.
    Any help appreciated.
    Thank you,

    User,
    Have a read about Java [url http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html]decimal format
    John

  • Separating number in inputext with comma

    hi all
    I need to separate numbers with comma without using Enter .
    I have an input text and used an clientListner on it : code is bellow
      <f:view>
        <af:document id="d1">  
         <af:resource type="javascript" source="/js/accounting.js"/>
         <af:resource type="javascript" source="/js/functions.js"/>
         <!--<af:resource type="javascript" source="/js/accounting.min.js"/>-->
          <af:form id="f1">
    <af:panelGroupLayout id="pgl1">
    <af:inputText label="Label 1" id="it1">
    <af:clientListener method="formatNum" type="keyUp"/>
    </af:inputText>
            </af:panelGroupLayout>
          </af:form>
        </af:document>
      </f:view>
    I run this JavaScript on HTML page that is OK and my input text show separated number during entering ,
    but I run my above jspx page ,it does not show until press the Enter key ...
    please guide me .... I have an emergency condition please answer me soon
    and then use this function for handling...
    function.js :
    function formatNum(evt) {
        var inputfield = evt.getSource();
        var num = accounting.unformat(inputfield.getValue());
        var formatNum = accounting.formatNumber(num);
        inputfield.setValue(formatNum);
        return true;
    accounting.js
    * accounting.js v0.3.2
    * Copyright 2011, Joss Crowcroft
    * Freely distributable under the MIT license.
    * Portions of accounting.js are inspired or borrowed from underscore.js
    * Full details and documentation:
    * http://josscrowcroft.github.com/accounting.js/
    (function(root, undefined) {
    /* --- Setup --- */
    // Create the local library object, to be exported or referenced globally later
    var lib = {};
    // Current version
    lib.version = '0.3.2';
    /* --- Exposed settings --- */
    // The library's settings configuration object. Contains default parameters for
    // currency and number formatting
    lib.settings = {
    currency: {
    symbol : "$", // default currency symbol is '$'
    format : "%s%v", // controls output: %s = symbol, %v = value (can be object, see docs)
    decimal : ".", // decimal point separator
    thousand : ",", // thousands separator
    precision : 2, // decimal places
    grouping : 3 // digit grouping (not implemented yet)
    number: {
    precision : 0, // default precision on numbers is 0
    grouping : 3, // digit grouping (not implemented yet)
    thousand : ",",
    decimal : "."
    /* --- Internal Helper Methods --- */
    // Store reference to possibly-available ECMAScript 5 methods for later
    var nativeMap = Array.prototype.map,
    nativeIsArray = Array.isArray,
    toString = Object.prototype.toString;
    * Tests whether supplied parameter is a string
    * from underscore.js
    function isString(obj) {
    return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
    * Tests whether supplied parameter is a string
    * from underscore.js, delegates to ECMA5's native Array.isArray
    function isArray(obj) {
    return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]';
    * Tests whether supplied parameter is a true object
    function isObject(obj) {
    return obj && toString.call(obj) === '[object Object]';
    * Extends an object with a defaults object, similar to underscore's _.defaults
    * Used for abstracting parameter handling from API methods
    function defaults(object, defs) {
    var key;
    object = object || {};
    defs = defs || {};
    // Iterate over object non-prototype properties:
    for (key in defs) {
    if (defs.hasOwnProperty(key)) {
    // Replace values with defaults only if undefined (allow empty/zero values):
    if (object[key] == null) object[key] = defs[key];
    return object;
    * Implementation of `Array.map()` for iteration loops
    * Returns a new Array as a result of calling `iterator` on each array value.
    * Defers to native Array.map if available
    function map(obj, iterator, context) {
    var results = [], i, j;
    if (!obj) return results;
    // Use native .map method if it exists:
    if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
    // Fallback for native .map:
    for (i = 0, j = obj.length; i < j; i++ ) {
    results[i] = iterator.call(context, obj[i], i, obj);
    return results;
    * Check and normalise the value of precision (must be positive integer)
    function checkPrecision(val, base) {
    val = Math.round(Math.abs(val));
    return isNaN(val)? base : val;
    * Parses a format string or object and returns format obj for use in rendering
    * `format` is either a string with the default (positive) format, or object
    * containing `pos` (required), `neg` and `zero` values (or a function returning
    * either a string or object)
    * Either string or format.pos must contain "%v" (value) to be valid
    function checkCurrencyFormat(format) {
    var defaults = lib.settings.currency.format;
    // Allow function as format parameter (should return string or object):
    if ( typeof format === "function" ) format = format();
    // Format can be a string, in which case `value` ("%v") must be present:
    if ( isString( format ) && format.match("%v") ) {
    // Create and return positive, negative and zero formats:
    return {
    pos : format,
    neg : format.replace("-", "").replace("%v", "-%v"),
    zero : format
    // If no format, or object is missing valid positive value, use defaults:
    } else if ( !format || !format.pos || !format.pos.match("%v") ) {
    // If defaults is a string, casts it to an object for faster checking next time:
    return ( !isString( defaults ) ) ? defaults : lib.settings.currency.format = {
    pos : defaults,
    neg : defaults.replace("%v", "-%v"),
    zero : defaults
    // Otherwise, assume format was fine:
    return format;
    /* --- API Methods --- */
    * Takes a string/array of strings, removes all formatting/cruft and returns the raw float value
    * alias: accounting.`parse(string)`
    * Decimal must be included in the regular expression to match floats (defaults to
    * accounting.settings.number.decimal), so if the number uses a non-standard decimal
    * separator, provide it as the second argument.
    * Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
    * Doesn't throw any errors (`NaN`s become 0) but this may change in future
    var unformat = lib.unformat = lib.parse = function(value, decimal) {
    // Recursively unformat arrays:
    if (isArray(value)) {
    return map(value, function(val) {
    return unformat(val, decimal);
    // Fails silently (need decent errors):
    value = value || 0;
    // Return the value as-is if it's already a number:
    if (typeof value === "number") return value;
    // Default decimal point comes from settings, but could be set to eg. "," in opts:
    decimal = decimal || lib.settings.number.decimal;
    // Build regex to strip out everything except digits, decimal point and minus sign:
    var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]),
    unformatted = parseFloat(
    ("" + value)
    .replace(/\((.*)\)/, "-$1") // replace bracketed values with negatives
    .replace(regex, '')         // strip out any cruft
    .replace(decimal, '.')      // make sure decimal point is standard
    // This will fail silently which may cause trouble, let's wait and see:
    return !isNaN(unformatted) ? unformatted : 0;
    * Implementation of toFixed() that treats floats more like decimals
    * Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present
    * problems for accounting- and finance-related software.
    var toFixed = lib.toFixed = function(value, precision) {
    precision = checkPrecision(precision, lib.settings.number.precision);
    var power = Math.pow(10, precision);
    // Multiply up by precision, round accurately, then divide and use native toFixed():
    return (Math.round(lib.unformat(value) * power) / power).toFixed(precision);
    * Format a number, with comma-separated thousands and custom precision/decimal places
    * Localise by overriding the precision and thousand / decimal separators
    * 2nd parameter `precision` can be an object matching `settings.number`
    var formatNumber = lib.formatNumber = function(number, precision, thousand, decimal) {
      // Resursively format arrays:
    if (isArray(number)) {
    return map(number, function(val) {
    return formatNumber(val, precision, thousand, decimal);
    // Clean up number:
    number = unformat(number);
    // Build options object from second param (if object) or all params, extending defaults:
    var opts = defaults(
    (isObject(precision) ? precision : {
    precision : precision,
    thousand : thousand,
    decimal : decimal
    lib.settings.number
    // Clean up precision
    usePrecision = checkPrecision(opts.precision),
    // Do some calc:
    negative = number < 0 ? "-" : "",
    base = parseInt(toFixed(Math.abs(number || 0), usePrecision), 10) + "",
    mod = base.length > 3 ? base.length % 3 : 0;
    // Format the number:
    return negative + (mod ? base.substr(0, mod) + opts.thousand : "") + base.substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + opts.thousand) + (usePrecision ? opts.decimal + toFixed(Math.abs(number), usePrecision).split('.')[1] : "");
    * Format a number into currency
    * Usage: accounting.formatMoney(number, symbol, precision, thousandsSep, decimalSep, format)
    * defaults: (0, "$", 2, ",", ".", "%s%v")
    * Localise by overriding the symbol, precision, thousand / decimal separators and format
    * Second param can be an object matching `settings.currency` which is the easiest way.
    * To do: tidy up the parameters
    var formatMoney = lib.formatMoney = function(number, symbol, precision, thousand, decimal, format) {
    // Resursively format arrays:
    if (isArray(number)) {
    return map(number, function(val){
    return formatMoney(val, symbol, precision, thousand, decimal, format);
    // Clean up number:
    number = unformat(number);
    // Build options object from second param (if object) or all params, extending defaults:
    var opts = defaults(
    (isObject(symbol) ? symbol : {
    symbol : symbol,
    precision : precision,
    thousand : thousand,
    decimal : decimal,
    format : format
    lib.settings.currency
    // Check format (returns object with pos, neg and zero):
    formats = checkCurrencyFormat(opts.format),
    // Choose which format to use for this value:
    useFormat = number > 0 ? formats.pos : number < 0 ? formats.neg : formats.zero;
    // Return with currency symbol added:
    return useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(number), checkPrecision(opts.precision), opts.thousand, opts.decimal));
    * Format a list of numbers into an accounting column, padding with whitespace
    * to line up currency symbols, thousand separators and decimals places
    * List should be an array of numbers
    * Second parameter can be an object containing keys that match the params
    * Returns array of accouting-formatted number strings of same length
    * NB: `white-space:pre` CSS rule is required on the list container to prevent
    * browsers from collapsing the whitespace in the output strings.
    lib.formatColumn = function(list, symbol, precision, thousand, decimal, format) {
    if (!list) return [];
    // Build options object from second param (if object) or all params, extending defaults:
    var opts = defaults(
    (isObject(symbol) ? symbol : {
    symbol : symbol,
    precision : precision,
    thousand : thousand,
    decimal : decimal,
    format : format
    lib.settings.currency
    // Check format (returns object with pos, neg and zero), only need pos for now:
    formats = checkCurrencyFormat(opts.format),
    // Whether to pad at start of string or after currency symbol:
    padAfterSymbol = formats.pos.indexOf("%s") < formats.pos.indexOf("%v") ? true : false,
    // Store value for the length of the longest string in the column:
    maxLength = 0,
    // Format the list according to options, store the length of the longest string:
    formatted = map(list, function(val, i) {
    if (isArray(val)) {
    // Recursively format columns if list is a multi-dimensional array:
    return lib.formatColumn(val, opts);
    } else {
    // Clean up the value
    val = unformat(val);
    // Choose which format to use for this value (pos, neg or zero):
    var useFormat = val > 0 ? formats.pos : val < 0 ? formats.neg : formats.zero,
    // Format this value, push into formatted list and save the length:
    fVal = useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(val), checkPrecision(opts.precision), opts.thousand, opts.decimal));
    if (fVal.length > maxLength) maxLength = fVal.length;
    return fVal;
    // Pad each number in the list and send back the column of numbers:
    return map(formatted, function(val, i) {
    // Only if this is a string (not a nested array, which would have already been padded):
    if (isString(val) && val.length < maxLength) {
    // Depending on symbol position, pad after symbol or at index 0:
    return padAfterSymbol ? val.replace(opts.symbol, opts.symbol+(new Array(maxLength - val.length + 1).join(" "))) : (new Array(maxLength - val.length + 1).join(" ")) + val;
    return val;
    /* --- Module Definition --- */
    // Export accounting for CommonJS. If being loaded as an AMD module, define it as such.
    // Otherwise, just add `accounting` to the global object
    if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
    exports = module.exports = lib;
    exports.accounting = lib;
    } else if (typeof define === 'function' && define.amd) {
    // Return the library as an AMD module:
    define([], function() {
    return lib;
    } else {
    // Use accounting.noConflict to restore `accounting` back to its original value.
    // Returns a reference to the library's `accounting` object;
    // e.g. `var numbers = accounting.noConflict();`
    lib.noConflict = (function(oldAccounting) {
    return function() {
    // Reset the value of the root's `accounting` variable:
    root.accounting = oldAccounting;
    // Delete the noConflict method:
    lib.noConflict = undefined;
    // Return reference to the library to re-assign it:
    return lib;
    })(root.accounting);
    // Declare `fx` on the root (global/window) object:
    root['accounting'] = lib;
    // Root will be `window` in browser or `global` on the server:
    }(this));

    hi all
    I have an input text that I want to separate it's value with comma
    this is my input text :
    <af:inputText value="#{bindings.LacreditAmt.inputValue}"
    label="#{bindings.LacreditAmt.hints.label}"
    required="#{bindings.LacreditAmt.hints.mandatory}"
    columns="#{bindings.LacreditAmt.hints.displayWidth}"
    shortDesc="#{bindings.LacreditAmt.hints.tooltip}"
    id="it8"
    maximumLength="#{bindings.LacreditAmt.hints.precision}"
    converter="converter.BIGDECIMALMONEYCONVERTER"
    clientComponent="true">
    <f:validator binding="#{bindings.LacreditAmt.validator}"/>
    <!--<af:convertNumber groupingUsed="false"
    pattern="#{bindings.LacreditAmt.format}"/>-->
    <af:clientListener method="handleNumberFormatConversion" type="keyUp"/>
    </af:inputText>
    and use this  java Script for comma separated value :
    problem is : when I used firebug for testing this java Script ,everything is OK and 'result' variable shown
    the correct value (comma separated value) but in fact the correct value did not show
    in input text  !!!!!
    please guide me soon.
    I appreciated in advance
    function handleNumberFormatConversion(evt){
            var inputField = evt.getCurrentTarget();
            var keyPressed = evt.getKeyCode();
            var oldValue = inputField.getSubmittedValue();
            var validKeys = new Array(48,49,50,51,52,53,54,55, 56,57,96,97,98,99,100, 101,102,103,104,105,AdfKeyStroke.ARROWRIGHT_KEY, AdfKeyStroke.ARROWLEFT_KEY, AdfKeyStroke.BACKSPACE_KEY, AdfKeyStroke.DELETE_KEY, AdfKeyStroke.END_KEY, AdfKeyStroke.ESC_KEY, AdfKeyStroke.TAB_KEY);
            var numberKeys = new Array(48,49,50,51,52,53,54,55, 56,57,96,97,98,99,100, 101,102,103,104,105, AdfKeyStroke.BACKSPACE_KEY, AdfKeyStroke.DELETE_KEY);
            var isValidKey = false;
            for (var i=0; i < validKeys.length; ++i){
                if (validKeys[i] == keyPressed) {
                    isValidKey = true;
                    break;
            if(isValidKey){
                    var isNumberKey = false;
                for (var n=0; n < numberKeys.length; ++n){
                    if(numberKeys[n] == keyPressed){
                        isNumberKey = true;
                        break;
                if(isNumberKey){
                    var formatLength = 25;
                    if(formatLength == oldValue.length){
                        inputField.setValue(oldValue);
                        evt.cancel();
                    else {
                        var firstNeg = false;
                        var lastNeg = false;
                        if (oldValue.charAt(0) == '(')
                            firstNeg = true;
                        if(oldValue.contains(')')){
                          lastNeg = true;                              
                        oldValue = oldValue.replace('(', "");
                        oldValue = oldValue.replace(')', "");
                        var result = "";
                        while (oldValue.contains(",")) {
                            oldValue = oldValue.replace(",", "");
                        for (i = oldValue.length - 3;i > 0;i -= 3) {
                            result = ",".concat(oldValue.substring(i, i + 3), result);
                        result = oldValue.substring(0, (oldValue.length % 3 == 0) ? 3 : oldValue.length % 3).concat(result);
                        if (firstNeg)
                            result = '(' + result;
                        if (lastNeg) {
                            result = result + ')';
                        inputField.setValue(result);
                        evt.cancel();
                        return true;                   
            else {
                inputField.setValue(oldValue);
                evt.cancel();

  • Currency with commas

    Hi all,
    I have a problem of displaying currency fetched from KONP table with commas.
    Its not related to displaying the currency with commas.
    I want to store the fetched value of currency with commas into some variable for further processing.
    Scenario>>
    If currecny value is 1000 in KONP,then i need this value to be stored in some variable as 1,000.
    Thanks,
    Anurodh

    Hi,
    you can use the WRITE statement to get the thousand seprator..
    l_curr = '1000'.
    WRITE l_curr to l_char. " l_char will hold 1,000

  • Currency field to be displayed with commas and asterisks(formatting)

    I have a field REGUH-RWBTR in my sap script code. I need to have the currency displayed with commas. And also if the digits are less, then left pad it with asterisks for remaining spaces.
    For eg, If the Digit is 12345678912.23 (max value), it should print as 12345,678,912.23.
    And If the digit is 12345.89, it should print as ******12,345.89
    Please help me to solve this problem.Its urgent.
    Thanks,
    Sandeep.

    Hello,
    You can use the WRITE using EDIT MASK.
    USING { {NO EDIT MASK}|{EDIT MASK mask} }
    Effect
    This addition overrides a conversion routine defined through reference to the ABAP Dictionary. The addition NO EDIT MASK only switches off the execution of an assigned conversion routine. The addition EDIT MASK calls either another conversion routine or defines an edit mask. For mask, a data object of the same name is expected.
    In order to call an arbitrary conversion routine CONV, mask must contain two equals signs, followed directly by the name of the conversion routine: "==CONV". During output, the content of dobj is passed to the function module CONVERSION_EXIT_CONV_OUTPUT, converted there, and then the result is displayed. If the function module is not found, an exception that can be handled is triggered (as of Release 6.10). The statement DESCRIBE FIELD contains an addition in order to fill mask accordingly.
    If the output length is specified explicitly with len, the conversion routine is executed for the specified length; otherwise for the implicit output length. If * or ** is specified for the output length, the appropriate rules are used for the converted result.
    If the first two characters in mask are not equals signs, the content is interpreted as an edit mask in which some characters have a particular meaning. The WRITE statement does not then output the content of dobj directly, but the character string in mask as follows:
    If the first two characters in mask are "LL" or "RR ", these are not output, They control whether the edit mask is left-justified or right-justified. If the first two characters are other characters, the edit mask is left-justified.
    All "_" characters are replaced from the left (in the case of "LL") or from the right (in the case of "RR") with characters for character-type types or numbers for the types p or i from dobj. In the case of fields of type c, closing blanks are ignored. Data objects of type f or x are converted into type c before editing. Superfluous characters "_" in mask are replaced by blanks. Characters from dobj for which there are no characters "_" in mask are not displayed.
    If dobj is of type i or p, the first character from the left "V" in mask is replaced with "-" in the case of a negative number and by blank in the case of a positive number.
    All the other characters of the edit mask are displayed unchanged.
    If no output length is specified, the implicit output length of dobj is used. If len is specified for the output length, the value of len is used. If * is specified for the output length, exactly that length that is required for the list display is set. If, in Unicode systems, characters of the edit mask are replaced by characters that take up more than one column on the list, the output length is increased accordingly and the output is filled with blanks in the list buffer. If ** is specified for the output length, double the length of the edit mask mask is used.
    If other formatting options are specified concurrently for an edit mask, these are used first and then the special characters in the edit mask are replaced by the interim result. The date masks date_mask are an exception to this. If these are specified, the edit mask is ignored.
    Notes
    In Unicode systems, you must remember that a character "_"in the edit mask does not necessarily correspond to a column in the list display since the space required in the display depends on the character to be replaced.
    The minus sign for a negative number is not displayed if no edit character "V" is specified. The decimal separator of a packed number with decimal places must be specified at the required position in the edit mask.
    Example
    Edited output of time duration. In the first output, the function module CONVERSION_EXIT_DURA_OUTPUT is executed. This converts the duration specified in seconds into minutes. In the second output, the edit mask is output according to the above rules. However, the underscore characters "_" are replaced by the characters from time.
    DATA: dura TYPE i,
          time TYPE t VALUE '080000'.
    dura = sy-uzeit - time.
    time = dura.
    WRITE /(30) dura USING EDIT MASK '==SDURA'.
    WRITE /(30) time USING EDIT MASK
                           'RRThe duration is __:__:__'.
    Regards,

  • Restricting input to integers, display with comma separators

    I'm using Acrobat 8 on a Macintosh. My question is very similar to the previous one about truncation. I have a small array that adds and subtracts fields, and sums them to totals. The following scripts restrict the data entry exclusively to numbers, but my problem is that it doesn't display my fields in Acrobat with comma separators, e.g., 123,456. Is there a better way of doing this, or is it just a matter of adjusting the formatting script?
    Using a custom script under Format:
    Custom Format script:
    event.value = "(" + eventvalue +")";
    Custom Keystroke Script:
    event.rc = /^[0-9]*$/.test
    (event.change);
    Bill Lomax

    I'm not aware of any cultures that allow multiple consecutive separators, and of course "en-US" certainly doesn't. I think you answer is just that TryParse isn't as smart as you would like it to be.
    If you know how many digits there are after the decimal point, you could use ToString to convert the decimal back to a string and verify that it is the same as the original string. For example, if the string has a currency symbol, thousands separators and
    two decimal places, you could use the following:
    Dim result As Decimal
    Decimal.TryParse(Me.tbxkWhCost.Text, System.Globalization.NumberStyles.AllowThousands _
    Or Globalization.NumberStyles.AllowDecimalPoint Or Globalization.NumberStyles.AllowCurrencySymbol, Nothing, result)
    If result.ToString("C2") = Me.tbxkWhCost.Text Then
    'String is good
    Else
    'String is bad
    End If
    I realise that this doesn't work if you don't know what format the number will be in.

  • WAD Graph-  Value Axis display value with commas

    Hi Gurus,
    In the WAD graph Value Axis displaying the value from 0 to 40000 like below
    40000.
    30000.
    20000.
    10000.
            0.
    But we want to display with comma for every 3 digits(1000). like
    40,000.
    30,000.
    20,000.
    10,000.
              0.
    Please do needful.
    Regards,
    Kiran A
    Edited by: Kiran A on Oct 21, 2009 6:00 PM

    Hi Kiran A,
    you can do it as follows:
    Edit Chart->Refine->Value axis->Line->Format-> here you have to put: 0,
    That is all
    Regards
    Erwin

  • Formatting a number element with commas and decimals.

    I have a dataset with numbers.  I already set the column type to "number".
    I want to format the number data with commas and decimals.  I found a way to add decimals, but I'm still very confused how to do commas and to combine that with the decimal formatting.
    Also, how do I apply that to a repeat region in my spry region?
    Any help would be appreciated.  Thank you very much.

    I found this on one of the forum questions.
    Excel dont preserve the trailing zeros.
    try opening the xcel and type 5.0000 and tab out, it wont preserve the trailing zeros after decimal.
    try finding out how to disable the option in excel. if you do that, you will see what you send out from the report.
    But you can try to convert the number into a text by trying to append a space at the beginning. See if that would work.
    Thanks
    Swarna

Maybe you are looking for

  • How to edit a template gallery with not xml files?

    i bought a template and have edited too my satisfaction, however i am unable to add more pics to the gallery, i can add frames and pics in the pics/thumbs timeline, but they do not show, i can change the 12 pics in the original timeline without diffi

  • Upraded to 10.5.6 and two of my four displays are no longer "detectable"

    I was happily running 4 displays from my 2 graphics cards (9600XT and 9200) under 10.3.9. 3 x DVI (one of which is with the ACI adapter) and 1 running via VGA to a plasma TV. The 3 displays running from DVI were all "name" recognized in System Prefer

  • Mygrating Asset GL Balances from Legacy to SAP

    Hello Gurus, We are Migrating GL balances from legacy system to SAP system. I would like to know whether there is any other transaction code other than OASV for fixed assets GL migration from Legacy to SAP system. Can we use F-02 transaction code for

  • Display CGM Files in Flash ?

    Is it possible to display CGM files (Vektor Drawings) in Flash ?

  • ITS version compatabiity with ECC 6.0

    Hi Experts, I have to install ITS (server components) at one of my client side to some transaction on web, earlier they were using R/3 4.6 and they switched to ECC 6.0 Please tel me which ITS version is comatable with ECC 6.0 I installed server compo