How to covert Decimal

I am trying to set twp decimal places in my result . I used
DecimalFormat and Round , I can get round for one decimal
palce but I need two decimal instead of one.
Since I am new for programming I may be not know to implement
Decimal format or round . I need help.
here is may code.
public class Circle {
public static final double pi = 3.14159;
double x = 5.00;
double y = 3.00;
double r ;
Circle(double x, double y, double r) {
r = 5.0;
x = 20.0;
y = 15.0;
this.x = x;
this.y = y;
this.r = r;
Circle() {
public double circumference() {
return 2 * r * pi;
public double area() {
return pi * r * r;
public void setRadius(double r) {
double Max;
Max = 30;
r = 5;
if ( r > Max) {
r = Max;
public void printAttributes () {
System.out.println(" Circumference is:" + circumference() );
System.out.println(" Area is:"+ area() );
System.out.println(" Radius is :"+ 2*pi / circumference() );
System.out.println(" Coordinates are + x , + y ");
public boolean isInside ( int x, int y) {
double dx;
double dy;
dx = x - this.x;
dy = y - this.y;
double dist ;
dist = Math. sqrt(dx * dx + dy * dy);
return (dist < r);
// if (dist < radius )
// return true;
//else
// return false;
void boundingBox() {
double tlx = x - r;
double tly = y - r;
double brx = x + r;
double bry = y + r;
//Top left Coordinators = tlx + tly;
//Top right Coordinators = brx + bry;
System.out.println( " Top left Coordinators: +tlx , +tly " );
System.out.println( " Top right Coordinators:+brx , +bry" );
void move (int x , int y) {
this. x = x;
this. y = y;
public static void main ( String args [] ) {
/**public static float roundUp (float value){
     int num ;
value=(float)(value*1000+.5);
     num=((int)value);
float d=(float)num;
d=d/1000;
return d;
Circle C = new Circle ();
C. r = 2.0;
C. x = 5.0;
C. y = 3.0;
Circle area = new Circle ();
Circle circumference = new Circle ();
//Circle Coordinators = new Circle (5, 3);
C. circumference ();
C. area ( );
C. printAttributes ();
C. move (-4, 5);
C. boundingBox () ;

I don't really understand your post so I'll just give you an example.
If I had a radius (in double format) and I wanted to return the circumference in double format rounded to 2 decimal digits, I would use this code:
    double radius = 5.00;
    BigDecimal tmp = new BigDecimal(radius * Math.PI * 2); // 2 * PI * R
    tmp = tmp.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    double circum = tmp.doubleValue();
    return circum;And if I wanted the area, I'd use this code:
    double radius = 5.00;
    BigDecimal tmp = new BigDecimal(Math.pow(radius, 2.0) * Math.PI); // 2 * PI * R
    tmp = tmp.setScale(2, BigDecimal.ROUND_HALF_EVEN);
    double area = tmp.doubleValue();
    return area;Just apply that to your code.

Similar Messages

  • How to maintain decimal places in BOM Qty & what is the essence of base qty

    Hello PP members
    How to maintain decimal places in BOM Qty & what is the essence of base quantity in BOM ?
    Thank You

    ur first question is not understood, You can have maximum of 3 decimals in BOM item qty.
    Base qty is the qty which is refered to all the BOM items.
    example -
    Product X, base qty 1
    Raw material 1 - componen t qty= 1
    Raw material 2 - Component qty= 5
    This means To produce Product with qty1, it needs raw material 1 qty 1  and raw material 2 qty 5.
    This means To produce Product with qty10, it needs raw material 1 qty 10  and raw material 2 qty 50.
    This is the meaning of Base qty..it is the referece qty refered to all the components.
    About the decimal places
    let us say  example 2
    To produce Product with qty1, it needs raw material 1 qty 1  and raw material 2 qty .0001.
    When you enter this in SAP for the raw materialm 2 system will give error message that you  need to enter the qty with maximum 3 decimal places, hence you need to enter as below
    Product with qty10, it needs raw material 1 qty 10  and raw material 2 qty .001.
    This is how you need to adjsut the base qty and component qty with decimalplaces moer than 3,
    pl come back

  • How to covert the Digits into Barcode

    hi friends,
    how to covert the numbers into Barcode notation in java
    pls help me out.

    Hi,
    See http://jbarcode.ronisons.com/doku.php
    Hope that help,
    Jack

  • How to covert  from .srf  form to xml form

    hi.....  plz anybody help me  to find this soloution... i am  not familiar with this enviorment
    how to covert  from .srf  form to xml form,
    it's very needed
    plz help me.................

    Hi Raj,
    You can do that way, but at times what happens is, if u try changing the extension while saving it saves as "<b>Form.xml.srf</b>" wherein, still its recognized as a srf file.  So, you save it as an srf first, and then, change (rename) the extension from .srf to .xml
    Satish.

  • How to insert decimal point while selecting data from a table

    Hi All ,
    My select requirement says , If the value received with no decimal then insert decimal before last 2 bytes. I need to retrieve data with this condition.
    May you people help how i can achieve this?
    Thanks in advance,
    Sachetan

    Is the data a number in string format?
    with q as (select '12345' myNum from dual
    union all select '45.78' from dual)
    select case when instr(myNum, '.') > 0 then to_number(myNum) else
           to_number(substr(myNum, 1, length(myNum) - 2) || '.' ||
                    substr(myNum, length(myNum) - 1)) end newNum from q
    NEWNUM
    123.45
    45.78If not just use
    with q as (select 12345 myNum from dual
    union all select 45.78 from dual)
    select case
    when instr(myNum,'.')>0 then myNum
    else myNum/100
    end myNum
    from q
    MYNUM
    123.45
    45.78

  • How to load decimal values into a file using bcp in SQL Server 2000?

    Hi everyone,
    I'm trying to load data from a database table to a text file using bcp on SQL Server 2000. When I'm loading the decimal values, the values before the decimal are not being loaded into the file. How could I load the values before decimals?
    Here are the DDLs and DMLs of what I'm trying to run:
    CREATE TABLE [dbo].[Product_Sales](
    [Year_of_Sale] [smallint] NOT NULL,
    [Product_Type] [varchar](25) NOT NULL,
    [Product_Group] [varchar](25) NOT NULL,
    [Category_Type] [varchar](25) NOT NULL,
    [Category_Group] [varchar](10) NOT NULL,
    [Product_Count] [bigint] NOT NULL,
    [Product_Amount] [decimal](19, 2) NOT NULL,
    [Category_Count] [bigint] NOT NULL,
    [Category_Amount] [decimal](19, 2) NOT NULL,
    CONSTRAINT [PK_Product_Sales] PRIMARY KEY CLUSTERED
    [Year_of_Sale] ASC,
    [Product_Type] ASC,
    [Product_Group] ASC,
    [Category_Type] ASC,
    [Category_Group] ASC
    ) ON [PRIMARY]
    ) ON [PRIMARY]
    INSERT INTO [Yearly_Sales].[dbo].[Product_Sales]
    VALUES(2010, 'Online', 'Web', 'Cameras', 'Electronics', 547, 0.00, 0, 0.00)
    EXEC [master].[dbo].[xp_cmdshell] 'bcp "SELECT * FROM [Yearly_Sales].[dbo].[Product_Sales]" queryout D:\Yearly_Sales\Product_Sales.dat -c -T -S'
    And the output I see in the file is:
    2010 Online Web Cameras Electronics 547 .00 0 .00
    The values before decimals are being truncated.
    Thanks,
    Bangaaram
    Known is a DROP, Unknown is an OCEAN.

    You can modify the decimal column(s) in the table to varchar type before export. But it does not look good.
    alter table [dbo].[Product_Sales]
    Alter column [Product_Amount] varchar(20)
    alter table [dbo].[Product_Sales]
    Alter column [Category_Amount] varchar(20)
    Does that make any sense?
    Known is a DROP, Unknown is an OCEAN.
    Basically you modify the decimal column to a varchar type before you run the bcp command for export. You can modify your source table or you can modify them on the fly. It is just a workaround.
    Modifying the source wouldn't be a good idea. Never do that if you can't get your desired output.
    Known is a DROP, Unknown is an OCEAN.

  • How to keep decimal in sql query

    Dear Expert,
    I try to do calculation in sql query, but it will automatically remove the decimal point.
    This is my query:
    SELECT 719 / 100
    And i want a result = 7.19, but its not work. Its return 7.
    i did try to use, SELECT ROUND(719/100,2), but its not working too...
    Does any one have any idea how to get 7.19
    Thanks in advance for any reply.
    Regards,
    Mat

    yes, i have answer already.
    select cast(719/(100*1.0)as decimal (16,2))

  • How to delete decimal point and adding leading zeros....

    Hi,
    I have one requirement in the report   i.e.
            <b>Present Value    :</b>  44567.98
            <b>Expected Value  :</b> 0000004456798
    In the present Value how will I remove that decimal point and how to add those six ing zeros. I tried with CONVERSION_EXIT....but it is not giving. Help me...
    Thanks in advance.
    Regards,
    Kumar.

    Hi,
    Use SPLIT and COMCATENATE fnctions.
    Eg:  split l_v at '.' into l_v1 l_v2
            concatenate l_v1 l_v2 into l_v.
    For adding leading zeros
    Use FM CONVERSION_EXIT_ALPHA_INPUT.
    Eg:
    data: tknum type vttk-tknum value '99156'.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
         exporting
              input  = tknum
         importing
              output = tknum.
    Sri
    Message was edited by:
            Sri Tayi

  • How to process decimal field in extract

    Hi All
    I need to use a extract in TableMaintenace event.
    I understood using loop and indexing, we can access teh fileds.
    But when i checked in the Debugging mode, Decimal values in hte table are displayed as ####. How to get these decimal fields.
    Could someone please clarify this?

    Increase the field length for you decimal field.
    If that doesn't work define the field as an alpha field.

  • How to get decimal notation in 'SU01'?

    Hi guys,
    You know that when we process the currency, it needs to know what the user have set the decimal notation.
    You can run tcode 'SU01',click the tab 'default' to see it.
    So how to get the user the setting?
    Any function module ?
    Welcome any ideas.
    Thanks very much.
    --James Liu

    make use if table
    USR01
    USR01-DCPFM     XUDCPFM     CHAR     1     0     Decimal notation
    possible values:
              1.234.567,89
         X     1,234,567.89
         Y     1 234 567,89
    regards
    Prabhu

  • How to display decimal values (8.00, 8.01, 8.10)

    Can you please tell me anyone how to display the decimal values.
    Ex: amount number(5,2)
    inserted the table value 300.00
    when I am select the value using it has to display as the same 300.00.
    Thanks,
    Ramesh

    I suggest you read oracle documentation about TO_CHAR function and number format models.
    SQL> select to_char(0.00, '99990.99') from dual ;
    TO_CHAR(0
    0.00
    1 row selected.
    SQL> select to_char(99.78, '99990.99') from dual ;
    TO_CHAR(9
    99.78
    1 row selected.
    SQL>

  • How to delcare decimal value in selection screen

    hi all,
    in my selection screen, how to declare parameter  type decimal value of 2 places default value 99.00 %
    points will be rewarded
    thanks in advance

    Hi,
    Create a domain for that variable.
    ex: val type P decimals 2.
    Assign it to data element.
    Then use that data element in u r selection screen.
    Reward if useful.
    Regards,
    Narasimha

  • How to avoid decimal places in smartorms

    hi friends,
    i have to display a field VBAP-KWMENG (order quantity) in samrt forms it has a value 1.000  but it is display ing as 1,000.
    how can i avoid those zeroes after the 1 my req is to print 1.
    KWMENG is a data element with packed decimal as (15,3).
    i tried VBAP-KWMENG(Z), VBAP-KWMENG(T) , VBAP-(KWMENG(K),
    but it is not supprssing those zeroes.
    pls urgent........
    thanks in advance.
    VENUMADHAV

    Hi
    Declare a local Variable in the program line.
    L_display of type char .
    Pass 1 to l_display .
    In the ouput field pass &l_display& .
    Hope this helps .
    Praveen

  • How to decrease decimal places in invoices

    Good day,
    How do i drecrease decimal places in invoices. For example , i have set the decimal places to 4 for costing purposes but i want the final invoice to be 2 decimal places for display purposes. i have tried decreasing the decimals using the decrease decimals icon but the decimals are still 4.
    Thanks

    Hi Wendy,
    This is System Standard that If you increased Decimal Place then you can not decrease those decimal Place again.
    If you want this then you can do this in (Print of Document) Document Layout through Crystal Report.
    Hope this help
    Regards::::
    Atul Chakraborty

  • How to put decimal in the substring function

    Hi Friends
    I am having a input value which is a UDF named GetValue which is mapped with a substring (0,4) which is again mapped to a split by value and then to the target field MENGE
    My problem is when value is coming from GetValue and i am mapping it to substring there i want to take the decimals also
    forexample let us value coming is 2 than in the substring and then to the target field i want to send as 2.000.
    Please help me how it can be done.
    Thanks

    Hi Aquarian,
    The value which is coming from GetValue UDF, map that to a FormatNumber Function
    Use the standard function 'formatnumber' with number format 0.00
    double click on 'formatnumber' function in mapping editor to get number format field.
    you need not put anything in the 'decimal separator' field.
    this function is available in arithmetic set of standard functions.
    I believe this should be it.
    Let me know if you need more help.
    Thanks,
    Varun

Maybe you are looking for