miércoles, 27 de diciembre de 2006

Formatting Numbers for Currency Display in JavaScript

by George Chiang of JavaScriptKit.com

Formatting numbers so they confirm to a specific format can be deceivingly tricky. For example, one of the most common tasks is to format a number for currency display- an integer followed by two decimals. You may be tempted to use number rounding to first shift the number's decimal places (via multiplication), round it, then shift the decimal back (via division) to pound the number into your hard earned dollar, though that won't work in many cases. For example, consider the number 120. Number rounding certainly won't get you to 120.00.

To easily format numbers for a specific number of trailing decimals or total digits (aka padding), JavaScript 1.5 introduces the below two nifty methods:

Number.toFixed(x): Formats any number for "x" number of trailing decimals. The number is rounded up, and "0"s are used after the decimal point if needed to create the desired decimal length.

Number.toPrecision(x): Formats any number so it is of "x" length. Also called significant digits. A decimal point and "0"s are used if needed to create the desired length.

-Number.toFixed()
The best way to see all the subtleties of toFixed() is to see it in action:var profits=2489.8237
profits.toFixed(3) //returns 2489.824 (round up)
profits.toFixed(2) //returns 2489.82
profits.toFixed(7) //returns 2489.8237000 (padding)
Displaying any number in currency format can't get any easier!

-Number.toPrecision()
To toPrecision() now:var anumber=123.45
anumber.toPrecision(6) //returns 123.450 (padding)
anumber.toPrecision(4) //returns 123.5 (round up)
anumber.toPrecision(2) //returns 1.2e+2 (you figure it out!)
toPrecision() is useful if your number must be of a certain length.

Browser Considerations
Now, as noted, our two heros above are JavaScript 1.5 methods. What this means is that they'll only work in IE5.5+ and NS6+. The issue of legacy browsers not performing the desired formatting operation not withstanding, how do you ensure that these two methods at least degrade well? Well, by using method detection in your code. For example:var profits=2489.8237

if (profits.toFixed) //if browser supports toFixed() method
profits.toFixed(2)

For those of you who also need to ensure legacy browsers such as IE5 also perform the desired number formatting operation, well, then it's time to roll your own function.

Article credits: George Chiang is the webmaster for JavaScriptKit.com, where he writes tutorials and scripts pertaining to JavaScript and web design.

lunes, 18 de diciembre de 2006

ColdFusion (4.5.1 and 5): Server crashes when using JDK 1.3 on Solaris or Linux

Macromedia ColdFusion Server versions 4.5.1 and 5 will crash for customers running JDK 1.3 on Solaris and Linux platforms. ColdFusion customers use JDK to run ColdFusion custom tags (CFX tags) in Java, or the ColdFusion cfobject tag for Java objects. This article describes a workaround for this issue.

Customers experiencing this issue may find the following error message in their server.log:

# HotSpot Virtual Machine Error, Internal Error
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
"Fatal","TID=11","01/18/01","09:56:03",
"Caught a fatal signal (11)

Solution

For JDK version 1.3 to work with ColdFusion Server on Solaris or Linux, use the following steps:

For Linux:

  1. Add JAVA_HOME to the start script under CFHOME.

    The start script is typically located at: /opt/coldfusion/bin under default installations. On Red Hat Linux, if you use the RPM, install JDK in the default location; the JAVA_HOME would be located at:

    # Set during install
    CFHOME=/opt/coldfusion
    ODBCINI=$CFHOME/odbc/odbc.iniJAVA_HOME=/usr/java/jdk1.3
    Note: RPM is the native way to install, remove, manage programs on Red Hat Linux systems via the Redhat Package Manager. It will find potential conflicts, prior versions, and so forth. By default, it installs a product according to its default location, specified by the product, which in the case of JDK is located at /usr/java/.

    On Red Hat Linux, if you install from the tar.gz file, you can choose the path location. Installing from a tar.gz file unpacks the program wherever the archive is located at the time of execution. For instance, if you chose: /usr/java/jdk1.3/jre/lib/i386/hotspot/libjvm.so as the JDK path location, you would define your JAVA_HOME as JAVA_HOME=/usr/java/jdk1.3.
  2. Based on your JAVA_HOME, configure the LD_LIBRARY_PATH within the start script noted in Step 1.

    For instance, if your JAVA_HOME is /opt/j2re1_3_0, your LD_LIBRARY_PATH is:

    LD_LIBRARY_PATH=$CFHOME/lib:$JAVA_HOME/jre/lib/i386/hotspot:
    $JAVA_HOME/jre/lib/i386/native_threads:$JAVA_HOME/jre/lib/i386/


    (Although the above snippet appears on two lines, it should be entered as one line.)
  3. Go to the ColdFusion Administrator page. Click the Java tab and add/modify the following settings:
    • Java Virtual Machine Path: Specify the path to the libjvm.so (this location varies depending on where you installed the JDK).
    • Add System Option: java.lang.Compiler=NONE
    • Add Implementation Option:-XX:+AllowUserSignalHandlers
  4. Stop and restart the ColdFusion processes.

For Solaris:

  1. Add JAVA_HOME to the start script under CFHOME.

    The start script is typically located at: /opt/coldfusion/bin under default installs. If the JDK was installed with the default settings, the JAVA_HOME would be located at:

    # Set during install
    CFHOME=/opt/coldfusion
    ODBCINI=$CFHOME/odbc/odbc.iniJAVA_HOME=/opt/j2re1_3_0
  2. Based on your JAVA_HOME, configure the LD_LIBRARY_PATH within the start script noted in Step 1.

    For instance, if your JAVA_HOME is /opt/j2re1_3_0, your LD_LIBRARY_PATH is:
    LD_LIBRARY_PATH=$CFHOME/lib:$JAVA_HOME/jre/lib/sparc/hotspot:
    $JAVA_HOME/jre/lib/sparc/native_threads:$JAVA_HOME/jre/lib/sparc/


    (Although the above snippet appears on two lines, it should be entered as one line.)

    In summary, you must add the following entries to the LD_LIBRARY_PATH variable in the start script:

    $JAVA_HOME/lib/sparc
    $JAVA_HOME/lib/sparc/native_threads
    $JAVA_HOME/lib/sparc/hotspot
  3. Go to the ColdFusion Administrator. Click the Java tab and add/modify the following settings:
    • The Initial Heap Size setting for the "JVM and Java Settings" must be set at minimum to 4096Kb. The default setting is 1024Kb. With the default setting, the server crashes or becomes unresponsive. Increase this setting.
    • Java Virtual Machine Path: Specify the path to the libjvm.so (this location varies depending on where you installed the JDK). In most cases, the libjvm.so file is located at: $JAVA_HOME/jre/lib/sparc/client/.
    • Add System Option: java.lang.Compiler=NONE.
    • Add Implementation Option: -XX:+AllowUserSignalHandlers.
  4. Stop and restart ColdFusion processes.

    Note: Ensure that when defining the location of your libjvm.so file in the ColdFusion Administrator to specify the version of the libjvm.so in the /sparc/client directory.
SOURCE:

http://www.adobe.com/go/tn_17878







viernes, 15 de diciembre de 2006

Manejo del Form Scope en ColdFusion

Processing form variables on action pages

The action page gets a form variable for every form control that contains a value when the form is submitted.

Note: If multiple controls have the same name, one form variable is passed to the action page with a comma-delimited list of values.

A form variable’s name is the name that you assigned to the form control on the form page. Refer to the form variable by name within tags, functions, and other expressions on an action page.

On the action page, the form variables are in the Form scope, so you should prefix them with "Form." to explicitly tell ColdFusion that you are referring to a form variable. For example, the following code references the LastName form variable for output on an action page:


#Form.LastName#

The Form scope also contains a list variable called Form.fieldnames. It contains a list of all form variables submitted to the action page. If no form variables are passed to the action page, ColdFusion does not create the Form.fieldnames list.

jueves, 7 de diciembre de 2006

Instalacion de ColdFusion en Windows 2003 Server

Si en algun momento ha tratado de instalar ColdFusion en una maquina con Windows 2003 Server y el instalador simplemente se cierra sin decir nada, aqui esta su solucion:
Para instalar ColdFusion en Windows 2003 se tiene que activar el instalador (Install Anywhere)
dentro de los permisos de instalacion del Servidor siguiendo estos pasos:

1. Control Panel
2. System
3. Advanced
4. Performance --> Settings
5. Data Execution Prevention
6. Turn on DEP for all programs and services except those I select
7. Add...
8. Seleccione el archivo exe de instalacion de ColdFusion
9. Aplique los cambios
10. Intente de nuevo
Publicar