Trimming decimal places on a textfield

I have a program that calculates a double and puts it into a textfield. The problem is when i calculate it it reads all decimal places and i cant see the first few numbers. How can i trim it so that it cuts off after say 3 decimal places, or just at the end of the textfield

I don't recall the syntax offhand. Find that class in the API.
Then
// check the API for constructor details.
DecimalFormat formatter = new DecimalFormat(...);
String shortString = formatter.format(3.784321);
myTextField.setText(shortString);shortString will equal "3.784" if you set up the DecimalFormat correctly for 3 places after the decimal point.

Similar Messages

  • Need to trim decimal Places in data pulled in Financial report

    Hi All,
    We have a Financial report in which in partcular column, data is being pulled by the formula :
    <<CellText("Grid1", Cur, C(A), 1)>>
    Some cells in that column contains only text comments, some cells having numbers only.
    Issue is with the numbers. Numbers when pulled in FR are being dispalyed upto 6 decimal places, i.e. 1234 is displayed as 1234.000000.
    So if somebody can suggest how can we modify the formula so that we can display the numbers without decimal values. i means , numbers being pulled are displayed as 1234 only not like 1234.000000.
    Thanks,
    Satish

    Hi there,
    You can use the function Trunc(xxxxxxx, 0) where xxxx is your retrieved value which is considered as numeric.
    However, if I were you, I would concentrate on how to resolve the issue with the smartview submission.
    Regards,
    Thanos
    One Truth about...

  • How to get the number of decimal places configured for a site column

    Hi,
    I have a column 'SampleNumCol' of type Number, the number of decimal places to be displayed is configured as 2.
    The column conatins a value, but when retrieved programatically is displayed as 5.00000000  instead of 5.00.
    I am retrieving this column using listitem.Properties[field.InternalName].
    I need to trim the decimals based on  number of decimal places configured for the site column.
    How to get the number of decimal places configured for a site column?
    Thanks in advance,
    dhijit

    Get the field as SPFieldNumber and then check DisplayFormat which returns
    SPNumberFormatTypes
    SPFieldNumber numberField = list.Fields.GetFieldByInternalName("YourNumberFieldName") as SPFieldNumber;
    SPNumberFormatTypes numFormatType = numberField.DisplayFormat;

  • Displaying results with a decimal place of two. Forcing decimal place.

    Hi there,
    Im writing a simple calculation device.
    You input one digit and press one of two buttons to multiply it by a certain number and then the result is displayed. The result is displyed hiding the result of the button you didn't press and visa versa.
    I am having a problem displaying the result with a constant two decimal place.
    I am using strings and thus don't know how to do this.
    Here is my code:
    import flash.events.MouseEvent;
    //restrict the input textfield to only numbers
    txtinput.restrict = "0-9";
    //restrict the input textfield to only two characters
    txtinput.maxChars = 6;
    // event listeners
    btnW.addEventListener(MouseEvent.CLICK, WHandler);
    btnC.addEventListener(MouseEvent.CLICK, CHandler);
    btnW.addEventListener(MouseEvent.CLICK, hideC);
    btnC.addEventListener(MouseEvent.CLICK, hideW);
    //functions
    function WHandler (e:MouseEvent):void
              //white calculation
              var answerW:Number = Number(txtinput.text) * Number(0.90);
              txtWResult.text = answerW.toString();
    function CHandler (e:MouseEvent):void
              //colour calculation
              var answerC:Number = Number(txtinput.text) * Number(0.99);
              txtCResult.text = answerC.toString();
    function hideC (e:MouseEvent):void
              //Hide colour result
              txtCResult.visible = false;
              txtWResult.visible = true;
    function hideW (e:MouseEvent):void
              //Hide white result
              txtWResult.visible = false;
              txtCResult.visible = true;
    After having a look online I have found these two resources:
    http://helpx.adobe.com/flash/kb/rounding-specific-decimal-places-flash.html
    and
    http://stackoverflow.com/questions/11469321/decimals-to-one-decimal-place-in-as3
    But I am confused when combining these techniques with strings.
    Any help would be greatly appreciated,
    Thanks in advance
    Mr B

    Use the toFixed() method of the Number class instead of the toString() method.  The result of it is a String with the number of decimal places you specify.
              var answerW:Number = Number(txtinput.text) * Number(0.90);
              txtWResult.text = answerW.toFixed(2);
              var answerC:Number = Number(txtinput.text) * Number(0.99);
              txtCResult.text = answerC.toFixed(2);

  • Rounding off to two decimal places

    Hello,
    For simplicity, is there a method which will round off
    a double variable to two decimal places.
    Excample: if I have a result which equals 2.1999998
    and I want to display this as 2.20 in a TexTField.
    Any help would be much appreciated.
    Thanks

    If you are trying to do dollars and cents, I further recommend you use:NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
    String currencyOut = currencyFormatter.format(yourNumber);to format your numbers as they will give the correct precision for international currencies simply by setting the locale, and they will also automatically handle the currency symbols ($, DM FR, etc.)
    Doug

  • Rounding off to 2 decimal places

    Hi,
    I use "Double" for my calculations and since I am working with $$ ;-) I need to round it off at 2 decimal places. Any quick way to do this? or do I have to write some major code for that?
    Thanks

    This works for all the test cases. Try this
    import java.math.BigDecimal;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    class RoundOff {
         public static void main(String args[]) {
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.8"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.98"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-1.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-1.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-141.036"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-00.1"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("-0.0"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.98"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.0.54"));
              //RARE EXCEPTIONS BUT WONT OCCUR
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("0125."));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("0125.979.79E"));
              //RARE EXCEPTIONS BUT WONT OCCUR
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.2354"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.9874"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.999"));
              System.err.println(" FINAL OUT PUT >>> " + formatPrecision("173449.999"));
         private static String formatPrecision(String s) {
              if (s == null || s.trim().length() == 0) {
                   return "0.00";
              try {
                   if (Double.parseDouble(s) == 0) {
                        return "0.00";
              catch (java.lang.NumberFormatException nfe) {               
                   return s;
              double d = 0.00;
              int ind = s.indexOf('.');
              String dec = "";
              if (ind > 0) {
                   dec = s.substring(ind);
                   if (dec.length() == 1) {
                        s = s.concat("00");
                        return s;
                   if (dec.length() == 2) {
                        s = s.concat("0");
                        return s;
                   if (dec.length() == 3) {
                        return s;
              if (ind == -1) {
                   return s.concat(".00");
              try {
                   d = Double.parseDouble(s);
                   BigDecimal bd = new BigDecimal(d);
                   bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); //2 decimal places
                   d = bd.doubleValue();               
                   NumberFormat formatter = new DecimalFormat("0.00");
                   return String.valueOf(formatter.format(d));
              catch (java.lang.NumberFormatException nfe) {
                   return s;
    }

  • Rounding numbers to 2 decimal places

    Hello programming community,
    I have the following code to round my answers to 2 decimal places:
    double roundedValue;
    DecimalFormat twoDForm = new DecimalFormat ("#.##");
    roundedValue = Double.valueOf(twoDForm.format(value));The code works great and what i expect it to do. When I pass in really big decimal numbers (2.55555668) it correctly rounds it (2.56) but when it rounds the number and the last decimal is a zero it does not display this. (if the number ends up rounding to 4.50 , i want it to display it this way but it ends up getting rid of the 0. )
    If anyone has any ideas for a way to fix this please let me know.
    Thanks.

    the-java-guy-needs-help wrote:
    i thought that my equation would be causing a problem and that i might need to do a cast -- I relized that this is not the problem
    for the type of string i am using the ("0.00")
    After trying various things the string does work if im just outputing it to the screen but i also use this rounding in a method that needs to return a double so i still need to convert it to a double.
    I have tried various ways of converting string to double (Double.parseDouble) and i tried one that involved a trim() but both methods drop the zero.You've got a basic misconception still going on here. If you convert it to a double, there is no such thing as a trailing zero -- it's meaningless since it only has meaning for a String representation of a double and not the intrinsic number itself.

  • 2 Decimal Places

    I am writing a program for class for hairsalon products, it requires to have the price outputed, the way I have it now the output shows as one decimal place as example, if it was $4.00, it is outputting as 4.0, how can I make it look like 4.00, and how do I add the dollar symbol. My code is below.
    public class SortSalon
         public static void main(String[] args) throws Exception
              HairSalon[] shops = new HairSalon[6];
              int i;
              char sel;
              shops[0] = new HairSalon("Cut",8.00,15);
              shops[1] = new HairSalon("Shampoo",4.00,10);
              shops[2] = new HairSalon("Manicure",18.00,30);
              shops[3] = new HairSalon("Style",48.00,55);
              shops[4] = new HairSalon("Permanent",18.00,35);
              shops[5] = new HairSalon("Trim",6.00,5);
              System.out.println("\tMenu Sorted by\n\n\tService (a)\n\tPrice (b)" + "\n\tTime (c)");
              System.out.print("\n\ntEnter Selection (a, b, c): ");
              sel = (char)System.in.read();
              System.in.read();
              System.in.read();
              switch(sel)
                   case 'a':
                   servSort(shops, shops.length);
                   print(shops, "Sorted by service");
                   break;
                   case 'b':
                   priceSort(shops, shops.length);
                   print(shops, "Sorted by price");
                   break;
                   case 'c':
                   timeSort(shops, shops.length);
                   print(shops, "Sorted by time");
                   break;
                   public static void priceSort(HairSalon[] array, int len)
                        int a, b;
                        HairSalon temp;
                        int highSub = len - 1;
                        for (a = 0; a < highSub; ++a)
                             for (b = 0; b < highSub; ++b)
                             if (array.getPrice() >
                             array[b + 1].getPrice())
                                  temp = array[b];
                                  array[b] = array[b+1];
                                  array[b + 1] = temp;
                   public static void timeSort(HairSalon[] array, int len)
                        int a, b;
                        HairSalon temp;
                        int highSub = len - 1;
                        for (a = 0; a < highSub; ++a)
                             for (b = 0; b < highSub; ++b)
                             if (array[b].getMinutes() >
                             array[b + 1].getMinutes())
                                  temp = array[b];
                                  array[b] = array[b + 1];
                                  array[b + 1] = temp;
                   public static void servSort(HairSalon[] array, int len)
                        int a, b;
                        HairSalon temp;
                        int highSub = len - 1;
                        for (a = 0; a < highSub; ++a)
                             for (b = 0; b < highSub; ++b)          
                             if (array[b].getService().compareTo(array[b + 1].getService()) < 0)
                                  temp = array[b];
                                  array[b] = array[b + 1];
                                  array[b + 1] = temp;
                        public static void print(HairSalon[] s, String msg)
                             System.out.println(msg);
                             for (int i = 0; i < s.length; i++)
                                  System.out.println(s.getService() + " " + s[i].getPrice()
                                       + " " + s[i].getMinutes());

    go to this link
    http://java.sun.com/j2se/1.4.2/docs/api/
    scroll down to java.text, look for Class Summary and find DecimalFormat
    have a good read, who knows, you might end up loving java.

  • How to trim decimal????????

    I have writen a program which gives a output in double data TYPE.
    EX- 25.525899999
    Is there any method to trim the decimal point to 2 decimal places????????

    PrintWriter, PrintStream and Console all have a printf() method, and String has
    a static format() method.

  • Error while updating decimal places in general settings

    Hii All
             I have got an error while updating Decimal places in General Settings
    Cannot update while another user is connected to the company i have checked, there is no other user logged in, i could add other settings but the problem is only with Decimal Places
    Note : there are no postings yet, a fresh database for a new client
             what could be the possible reason
                                                                 thanks
                                                                         RIYAZ

    Hiii All
          As a forum rule, i have initially gone through with the existing threads and then i was force to post a thread,
              would be helpfull if there is any other way..
                                                Thanks
                                                         RIYAZ

  • Decimal places in report painter

    Hi experts.  I have a financial report written in report painter.  I want to show two decimal places on a single row.  The rest of the report is in whole dollars, but this one row is a percentage, so I want to show decimal places.  I know that you can format an entire column, but I can't figure out how to format a single row.  Can anyone help?
    Thanks
    Janet

    YES U CAN
    SAME AS ABOVE PROCEDURE
    BUT SELECT ROW INSTEAD OF COLUMN
    Edited by: Anil Kumar Potnuru on Feb 10, 2009 9:02 PM

  • Can not change the number of decimal places in the normalization of result

    dear all
        i want to see the proportion of some data, for example, the income of May is 300, and the total income is 1000, i need to display it like 33.33% . so i set the
    Calculate single values as normalization of result, and then it display 33.333%, i like to display only two number of decimal places, so i set the number of decimal places as 0.00, but i doesn't work, it still display three decimal numbers.
        maybe you say i can use the percentage function like %CT %GT %RT, but i need to allow external access to my query, so the i can not use those functions.
        can somebody helps me ? your advice is appreciated.

    hi,thanks for your advice, but that doesn't suit for my problem.
    before i set the normalization of result, i can change the decimal values. After that i cann't.
    In your thread, someone proposes use the T-code OY04. but this wouldn't help. As i change to other key figure, such as user quantity, when i set normalization of result, it still display 3 decimal values.
    i think the point maybe lie in the normalization of result. please advise... thanks...

  • Problems with decimal places and formatting

    Hi , we are having problems with an add on running on different localization companies. Decimal places separatd by "," differ from other localizations. We dont know if this is a SQL collation setting or somethng related to code or requirements to run add ons on different servers and languages.
    Any ideas??
    Thanks

    Hello
    Follow up with this thread:
    [Re: How to get the numeric value of DocTotal from UI API]
    Regards,
    J.

  • Decimal Places in Item Cost must be 6 characters while in Journal Entry 2.

    I have the following problem:
    Accounting needs to see and work with 2 decimal places, but the item cost is needed in 6 decimals.
    If I register a A/P Invoice and i go to the Journal Remark, the Journal Entry should be in 2 decimals. If i look for the Item Cost on the Wharehouse this cost should be in 6 decimals.
    Is there a way to handle Accounting in 2 units and Cost in 6 Units
    Thank You very much

    Hi Saul,
    The request appears illogical, how can the accountant work with 2 decimal places & the item valuation is held with 6? The stock account with 2 decimals will never match the stock audit report with 6 decimals.
    I'm afraid the SAP Business One core functionality does not cater for this need. There are no 'behind the scenes' journal entries. A JE is legally binding so you need to decide whether you wish to work with the most accurate calculations regarding item cost as possible (6 decimals) or accommodate the accountants & work with 2 decimals in the journals.
    You might want to take the nature of the stock into consideration, if there are huge quantities at small individual prices 6 decimals might be better, if you use mainly standard cost &/or have no major cost fluctuations when using MAP/FIFO, 2 decimals might be sufficient.
    All the best,
    Kerstin

  • Decimal places in standard input schedule templates

    Hi Gurus
    I have created some input schedules using standard template. User here will be entering some values in 2 decimal places (like 1.25) but when I enter any values in the cells, it automatically round off the values and displays values without any decimal places.
    I have tried changing the formats in Format control panel by changing the DATA / DEFAULT 's PATTERN / ALL for ROWs but it did not help.
    Please help how to resolve this.
    Cheers
    Swathi

    Hi nilanjan,
    Thanku, I resolved the issue using Format Range option with the below code
    CRITERIA    EVALUATE IN  FORMAT     USE     PARAMETERS    APPLY TO
    INPUT          ROW                1234,56      ALL                --                   DATA
    Thanku

Maybe you are looking for

  • Selection-screen design

    Hi everyone, I am working on a project for which I have to design a selection-screen. The requirement is such that there are 3 obligatory fields to be filled by the user, which are as follows: P_LAUFD(parameter,obligatory-date), P_LAUFI(parameter,obl

  • How to create colums with the same Field

    Hello every body, I have this report only with one field how i can create columns in base of rows for example some times  this field containing 40 rows then I need to create 2 columns of 20 that when is even or 15 then create 2 columns one with 8 row

  • Effect Question for PR

    How can I open a scene like this in PR?  Thanks for any help you can give me!!!!!!!!!! Lil Durk f/ Migos & Cashout - Lil Niggaz (Official Video) Shot By @AZaeProduction - YouTube Checkout what I am asking about from 17-42 seconds into the video and t

  • IPhone 6 plus won't rotate to landscape - small lock with circle around it

    I have an iPhone 6 plus - and I have an small icon that is a padlock with a circle around it - how do I unlock the screen orientation lock?

  • Mighty Mouse and wireless keyboard stop working

    Just got my iMac yesterday and everything worked out of the box. But once yesterday and once so far today, the wireless mighty mouse and keyboard stopped working. Today I noticed after the mouse stopped moving the cursor, the little green light on th