Format decimal number...

is anyway to format more than two decimal point using javascript?
for example 123.00000 ( 5 decimal point )
or using java code to format?

<%@ page contentType="text/html;charset=windows-1252"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Format decimal</title>
  </head>
  <SCRIPT language="javascript">
  function setDecimal(){
      var num = document.forms[0].num.value;
      var dec = "";
      var nums = "";
      if(isNaN(num)){
        alert('Not a number!');
        document.forms[0].num.value = "";
      }else{
        if(num.indexOf(".")>-1){
          dec = num.substring(num.indexOf(".")+1,num.length);
          if(dec.length<5){
            var num1 = 5 - dec.length;
            nums = num;
            for(var x = 0;x<num1;x++){
              nums = nums + "0";
            document.forms[0].num.value = nums; 
          }else if(dec.length>5){
            if(parseInt(dec.charAt(5),10)>4){
              nums = parseInt(dec.substring(0,5),10)+1;
            }else{
              nums = parseInt(dec.substring(0,5),10);
            nums = num.substring(0,num.indexOf("."))+"."+nums;
            document.forms[0].num.value = nums; 
        }else{
          document.forms[0].num.value  = num+".00000";
  </SCRIPT>
  <body>
  <form>
    <input type="text" name="num"/>
    <input type="button" value="format" onclick="setDecimal()" />
  </form>
  </body>
</html>

Similar Messages

  • How to format a number to a correct decimal places

    i wanted to format a number to a correct decimal places say for example
    666.105 t0 666.11 please any body help us

    whether to use NumberFormat or DecimalFormat can u give me example thanks

  • Format a decimal number to percentage form, e.g. 0.01 to 1%

    Hi all,
    As titles, i want to format a decimal number to percentage form, e.g. 0.01 to 1%. I can't find it in PQ.
    Thanks,
    Arthur
    Keep involved!

    PQ doesn't currently have a way to specify number formats (that's usually done in Excel after filling the data to the sheet, or in Power Pivot). But if you want to generate some text that represents a number as a percentage, you can use this formula:
    = Text.From(TheNumberYouWantToFormat * 100) & "%"
    Ehren
    Any plans to add this functionality in the future?
    Keep involved!

  • How to Format a number to support multiple languages

    I am trying to format a number so that it shows up with the corret decimal separators and thousands separators for different regions/languages, but can't seem to.
    123456.223 is 123,456.223 (US English) and 123 456,223 in French (France)
    I don't know how many such regional settings are being used and what the decimal and thousands separators are.
    If you set the Format to 'System Default Number Format', all is well (But I have to live with 2 digits after the decimal). However, if I want to customize it by saying choosing one of the preset formats or using 'Customize'(say 3 digits after the decimal, for example), then, if I am designing the report in US English setting, the separators from that setting are used, even when the report is generated in French locale. Even if I try to put in a condition for these separators and use 'DefaultAttribute', it doesn't seem to help.
    One workaround is to format the number as a string and display the string instead (this time use ToText() function and provide the no. of decimal places needed). But I have aggregations based on this field and they don't work in with string fields.
    Could someone advise me if there is a way to solve this problem? (I'm hoping that there is some way, perhaps an easy one to overcome this problem.) It seems anytime I want to change the default setting, the current values are stored and used irrespective of the reigonal setting.
    Any help is greatly appreciated.
    Thank you,
    Raghu

    Use the default settings and then it should format according to the local PC settings.

  • Format a number

    Hi,
    I need some help with formating a number.
    I am having a string object of format '00000' and i want to have it formatted to '000.00'
    Is there a way i can change it to double by specifying the format?
    Let me know if there is any way i can do it using Number format or Decimal format?

    Does this String come in any other flavors? Is it to represent currency? Myself, if this were currency, I'd read it in as an int and even save it and manipulate it as an int. Then when I wanted to display it, I'd divide by 100.00 and use a either a NumberFormat.getCurrencyInstance if it's currency, or else a DecimalFormat if not.

  • Comma or point in decimal number

    Hi,
    I wonder how to handle decimal number input from jsp page with comma or point. Is there a way to take care of this automatic so a comma get parsed to a point or vice versa.
    Thanks in advance.

    I don't know if it will be a comma or a dot that is inputed. My keyboard uses a comma on the numeric pad but if i change it to a US keyboard it will use dot instead so I can't tell what a user will input. And if I understand everything when java calculates a double it has to be with a dot, or am I completly wrong.
    So with this in mind i decided to replace all dots with a comma and then parse it to a double with NumberFormat and do my calculation and then format it with NumberFormat again. This works fine and gives me a nice output if no one tries to input more than one point or comma.
    I can't think of another way to do it so if this is completly wrong so please point me in the right direction.

  • How to convert fractional decimal number to hex number?

    Hi,
    Can any one help me to convert the fractional decimal number to its equivalent hex number and vice versa ?
    if u have any code please share.
    thanks
    neethu

    neethukk wrote:
    Can any one help me to convert the fractional decimal number to its equivalent hex number and vice versa ?
    if u have any code please share.
    This question is not clear at all.
    "Fractional decimal" is not a data type, but a way of formatting in readable form using numeric characters and a decimal separator.
    Same to "hex number", but only for integers.
    What do you mean by "convert"? Do you want to keep the value the same or retain the bit pattern of the numeric data type?
    Hexadecimal is for integers. Are you talking about fixed point?
    We clearly need significantly more information. What are the input and output data types? What are you actually trying to do?
    Do you have an example input and corresponding output?
    LabVIEW Champion . Do more with less code and in less time .

  • Apex 4.2: Date picker & format mask number

    Hello
    In Apex 4.2, in a Date Item, how can I modify the date picker to set Monday as the start of week day? I can set Monday as the start of week day on a calendar, but not in a Date Item.
    In a Number Item, there's no format mask to set the comma char as a decimal separator and the dot char as a thousand separator. How can I create a new format mask number?
    Thank you.
    Edited by: user7034195 on 12-mar-2013 3:24

    for the Date Item, you can check this link, you have to call the process on the page load
    http://stackoverflow.com/questions/1313317/set-start-day-of-the-week-in-jquery-ui-datepicker
    and for the Number format, there's a little trick involved, will try to explain
    First of all convert you items from Number field to simple Textfield.
    1. Write this in your items Post Calculation Computation: TO_CHAR (:item_name, '999G999G999G999G990D00', 'NLS_NUMERIC_CHARACTERS = '',.''')This will do the number formatting you want, but in oracle above format is not acceptable, so while submitting the above values to database we need to undo the changes for that you can use the below code.
    2. Create a Computation "After Submit" for every item you did the above formatting and copy this code in it: replace(replace('1.00.00,00','.',''),',','.') for the 2nd step you can create a package/function which will get the items value as string and do the conversion as number using above code and return back the number.
    This should help you.
    Regards,
    Tauceef

  • Add a date to decimal number

    hello
    pls tell me how to add a date to decimal number as
    4 years and 3 months for example ?
    EX.
    ===
    1/1/2001
    +
    4 years and 3 months
    Regards,
    Abdetu...

    If you want a specific result, then post your desired result...we don't know your desired format mask.
    In case it's yyyymmdd:
    SQL> select to_date('1/1/2001', 'dd/mm/yyyy') dt
      2  ,      add_months(to_date('1/1/2001', 'dd/mm/yyyy'), 51) dt2
      3  ,      to_number(to_char(add_months(to_date('1/1/2001', 'dd/mm/yyyy'), 51), 'yyyymmdd')) num
      4  from   dual;
    DT                  DT2                        NUM
    01-01-2001 00:00:00 01-04-2005 00:00:00   20050401
    1 row selected.

  • Output decimal number through GPIB or VISA

    I was wondering if it is possible to output a decimal number, as in not a string, through the GPIB or VISA commands. I am trying to communicate with a machine that I think wants to get a number, and can't understand what I am sending when it is in a string format.
    thanks

    It is possible to transmit such a number over GPIB. I would double check the instrument manual for what it requires. I'm going to assume that you are using a long to represent a floating pont number. Here is some example code for how you would pass this number to the GPIB ibwrt() function.
    int ud = ibdev(board,PAD,SAD,timeout,eot,eos);
    long myNumber = 4.2;
    ibwrt(ud, &myNumber, sizeof(long));
    Essentially, the driver will break down the 32-bit number into 4 8-bit chunks.
    Craig A.
    National Instruments Engineer

  • Formating decimal places

    What's the preferred way to format a number (which will converted to a string for display) to 2 decimal places?

    var someValue = 1234.567;
    var a = "{%10.2f someValue}";

  • 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

  • How to format a number to "+0000000000.123,45"

    Hi! my name is Jorge. My problem is that I need to format a number to a extrange format. I know how to change the decimal point, the number of integer and fraction, etc.
    But the problem is I want the number with N zeros at the begining but only with decimal point if there are digit. And I need the sign always appear, if it is a minus or a plus.
    For example:
    123,456.789 -> +0000000000123,456.789
    -1,234,567.890 -> -00000000001,234,567.890
    It is possible using a pattern. There is someone who show me how, because I can't find it the rigth pattern.
    Thank you very much,
    Jorge.

    Here play with this - you'll need to tidy it up a bit for numbers under a 1000 or a million - maybe a parseInt function // * here would do it - Anyway, its a start. I've written it in a drag 'n' drop style so you can test and play first beofre applying it. Thats what I usually do - though I seem to recall java programmers think that 'drag-n-drop' is a dirty term - NO OFFENCE GUYS _ I'M NEW !!!
    import java.text.*;
    public class Decimal_Fmt {
    public static void main (String []args) {
    double d = Double.parseDouble(args[0]);
    DecimalFormat fmt = new DecimalFormat("#0"+","+"000"+","+"000.0#####");
    // * Possibly add a function call here ? *
    String d_str = fmt.format(d);
    System.out.println("DecimalFormat: "+d_str);
    }

  • Format a number, pad with spaces

    I want a simple way to format a number into a String, but have it padded with spaces. My code started like this:
    DecimalFormat myFormatter = new DecimalFormat("###.00");
    String output = myFormatter.format(12.5);
    The output is '12.50' when I want ' 12.50' (leading space). There's got to be an easy way to do this!
    Thanks for your help

    What you probably wanted to do was print some numbers in a column (of JTextArea's, for example) so that the decimal points line up.
    I wasted some more time and came up with the following:  String formattedNumber = numberPad(number, "###.00E0");
      static String numberPad(double number, String format) {
        int desiredDecimalPosition = format.indexOf('.');
        DecimalFormat numFormat = new DecimalFormat(format);
        String formattedNum = numFormat.format(Math.abs(number));
        formattedNum = formattedNum.replace('E', 'e');
        int exponentPosition = formattedNum.indexOf('e');
        if (exponentPosition < 0)
          exponentPosition = formattedNum.length();
        formattedNum = formattedNum.replaceFirst("e0", "");
        int decimalPosition = formattedNum.indexOf('.');
        formattedNum = (number > 0 ? " " : "-") + formattedNum;;
        if (decimalPosition < 0)
          decimalPosition = exponentPosition;
        int padding = desiredDecimalPosition - decimalPosition;
        if (padding > 0)
          formattedNum = "        ".substring(8 - padding) + formattedNum;
        return formattedNum;
      }Now it turns out that- despite the fact that I've told DecimalFormat to format precisely 2 digits to the right of the decimal, it sometimes randomly gives me 3, and (less often) 1!
    All this trouble just to try save 16kB of Henrik Bengtsson's sprintf in my jar file...

  • Format a number 9999/99

    Hi,
    i want to format a number like this 9999/99, with a slash bar, how can i do that? is it possible ? or only numbers to currency format....
    thanks!

    Maybe using:
    If number grouping separator, decimal separator is configured in adf-faces-config.xml file, it will be used during call to getAsObject() and getAsString() for parsing and formatting. If it has not been set, number grouping separator, decimal separator is defaulted based on the locale.
    From http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/jsf/doc/tagdoc/core/convertNumber.html.
    Venkat

Maybe you are looking for

  • Computer is authorised but it won't let me play already purshased songs!!

    i just re loaded i tunes and I've not been on it for ages because of some problem with updating it all fixed, but I can't authorize the computer, for some reason its unauthorized itself and won't let me authorize it again and now i cant play songs or

  • Problem with dashed strokes

    I have a GeneralPath that I draw with two different BasicStrokes. The two strokes are (intended to be) identical except that one is dashed. What I'm observing is that in some cases the two stroked outlines do not overlap, as I'd expect them to. Are m

  • Alert for orphaned files (.mdf, .ldf & .ndf)

    Hi,  Has anyone got any code that can scan all attached drives/directories for database files and compare them to what the instance says are attached files?  I have some code which works but you have specify the directories to monitor.   I know that

  • Java WEB AS - Is it possible to prevent a single process using all memory?

    Hi all, We have a SAP PI 7.0 installation and we have encountered issues with Java mappings utilizing all available memory on the Java stack and causing the server to slow and eventually crash. The original issue was caused by a poorly coded map, but

  • Connecting the sale order sch line and delivery no

    I want to find a delivery no and item no which is created for a sale order-> item no->schedule line. Is there any table which relates even sch lines. I know VBFA is the table but i want in even connecting schedule lines. If we dont have table is thei