Truncating Decimal Values

Hi! Folks,
I would like to ask for you kind assistance in figuring out my assignment, how to truncate a decimal value depending on the number of decimal places the user has specified.
Your immediate assistance will be much appreciated.
Cheers!

// utility class
public class Fraction{
   public static double digits(double d, int places){
      return (long)(d*Math.pow(10,places)+0.5)/Math.pow(10,places);
   public static double digits(double d, long places){
      return (long)(d*Math.pow(10,places)+0.5)/Math.pow(10,places);
   public static float digits(float d, int places){
      return (int)(d*Math.pow(10,places)+0.5)/(float)Math.pow(10,places);
   public static float digits(float d, long places){
      return (int)(d*Math.pow(10,places)+0.5)/(float)Math.pow(10,places);
// testing class
public class Dec {
    public static void main(String s[]) {
        int decimalPlaces = 3;     
        double d = 2343.12894132134;
        d = Fraction.digits(d, decimalPlaces);
        System.out.println(d);
}

Similar Messages

  • ALV: issue in truncating decimal values (rounding up)

    Hi,
    I have been receiving a problem truncating decimal values in alv environment using this abap code.
    WRITE gwa_komv-kwert TO gv_out_tax CURRENCY rte0143sf-currency
            DECIMALS l_decimals LEFT-JUSTIFIED.
    where l_decimals = 0.
    More exactly the value is rounded up but this is not my expectation.
    Any idea?
    Thanks.
        Giovanni

    Standard behaviour with DECIMALS 0: rounding up or own.
    And when you use the addition DECIMALS, then the CURRENCY addition is ignored as well.

  • Decimal Values getting truncated

    Hi,
    In my query results, the decimal values are getting truncated.  e.g.
    0.30 + 0.44 = 0.70  (expected result = 0.74)
    0.30 + 0.45 = 0.80  (expected result = 0.75)
    0.40 + 0.48 = 0.80  (expected result = 0.78)
    What am I supposed to do to make sure that the second decimal point is not truncted.
    Thanks,

    Hi,
    I do not have any conditions.  Except that I am just using the function NODIM to get the decimal values in my report.
    I did tried using the decimal places in the Key Figure properties.
    Are there any other possibilities to solve this?
    Thanks,

  • Decimal values truncated from SQL Call through Oracle ODBC

    Hi
    I'm using Oracle ODBC driver v 9.02.00.06; when I make a SQL call to query data from the Oracle ERP (PO_Lines_All), my decimal values are truncated. Instead of getting 112.25, I only get 112
    Can someone help me fix this problem?
    thanks

    The problem is commonly related to a language difference between Oracle and SQL Server.
    Try setting HS_LANGUAGE=american_america.we8mswin1252 in the intialisatuion file of HSODBC.
    Then start a new SQL*Plis session and give it a try.
    If you still have problems, set it to:
    HS_LANGUAGE=german_germany.we8mswin1252 in the

  • 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.

  • Webi Report ignores decimal values

    Hi,
    I have a report which takes data from a BI Infocube. I have BOE XI 3.1 installed on two systems. When I run this report on one system, the report works fine and numeric values are displayed along with decimal values ( ex 100.25). However the same report when executed in the other system ignores the decimal values (ex 100).
    I check the preferred viewing locale in the preferences and it is set to default values in both the systems.
    I have no clue what could have gone wrong.
    Any inputs on this issue will be highly appreciated.
    Regards,
    Rahul Mainkar

    You are right. No Fix Pack is installed.
    Probably the system, which is NOT truncating the decimal part has been installed on a Windows server where the local system account has EN-US regional settings. This should not be the case for the system which is truncating your numbers.
    A work-around is to create a domain account which is member of the local administrators group on the BOBJ servers. You should log on once on each of your two servers using this account and adjust the Regional Setting (Start->Control Panel) to English-United States. Invoke the CCM utility and open the Properties window of your SIA and Tomcat. Enter the credentials of your new user in  the "Run as"  area and restart your services. This will solve your problem.
    Regards,
    Stratos

  • How to truncate the values from the table

    Hi All,
    I am working on an issue..where we are first deleting all the records from the table and then based on few conditions we are putting the records back in that table...when we tried to run this program along with few others those who are doing almost the same stuff we are having issues...we tried to schedule few jobs related to these programs only...but after a ceratin amount of time couple of jobs got canceled...I was talking to my basis guy and he said the problem is ratehr then truncating the records from the table we are deleting the records and it's taking lots and lots of space to execute...so we need to truncate the records from the table insted of deleting it...we are using the following the statement right now:
        DELETE FROM ZTUS_PG.
        COMMIT WORK.
    So can you please tell me how can we truncate the values from this table instead of just deleting them and what would be effect of this.
    Thanks,
    Rajeev Gupta

    I don't think basis is saying you should delete all the records from the table. They are saying remove the table and it's contents (a much faster thing to do). I'm not sure this the right thing to do, but you can have a look at:
    http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.apdv.sample.doc/doc/admin_scripts/s-truncate-db2.htm
    Something like:
    EXEC SQL.
      TRUNCATE TABLE ZTUS_PG REUSE STORAGE
    ENDEXEC.
    COMMIT WORK.                      "Empty table is committed here
    Rob
    Edited by: Rob Burbank on Dec 1, 2008 4:06 PM

  • How do I convert an alpha character from a text string to its decimal value

    I am trying to find out the actual decimal value of a character in a string. So far the code below is as far as I got. I am able to get what I guess is a byte value.
    This is for a school assignment:
    The idea behind what I am trying to do is to design a hash function to store dictionary words into a bucket array hash table, without using the existing Hashtable.class
    so far this is what I can come up with to get some kind of value for each character in the string, however, what I am trying to get is the decimal value for each character.
    public static void main(String args[]){
         String word = "abcdefghijklmnopqrstuvwxyz";
         for (int i=0 ; i < word.length(); i++){
         System.out.print((word.substring(i,i+1)));
         System.out.print("\t : "+((word.substring(i,i+1))).getBytes());
    Thankyou for any replies.

    I'm not sure I completly understand your goal- what you mean by "decimal value", but, if you simply want to find the byte value of each character in a String, you would probably be better off using getBytes() in a way like this,
    byte [] bytes = string.getBytes();
    Then, if you need to map that to a charcter, you could use a for loop like
    for (int x = 0; x < bytes.length; x++) {
    table.put((char)bytes[x], bytes[x]);
    which assummes this bucket class of yours allows primitive data types like so (in Hashtable or HashMap, you would have to use a wrapper Object). I guess, my point reduces to, don't use substring and string search methods (like indexOf()), unless you have to because they are more expensive then just maping the array of bytes and chars, which seems to be what you are interested in doing.

  • Decimal  values for a field in ALV

    Hi,
    I created an ALV report.
    It has a field which will display the calculated value as '103,839,389'. This should be dispalyed as '103,839,389.00' with decimal value, I mean with 2 decimal places, how can this be achieved?
    Thanks,
    Kumar

    hi check this..
    use these in populating the fieldcat..
    it_fieldcat-decimalsfieldname = fieldname
    it_fieldcat-decimalstabname   = tabname
    it_fieldcat- decimals_out   = 2.
    regards,
    venkat

  • ALV report - remove of decimal values

    Hi experts,
    In my ALV report, output table having decimal values, ex:90000.50, i want to display only 90000,
    can help any one inthis.
    Thanks in advance.
    Regards
    Rams

    Hi,
    for that particular field in Field catalog..
    <ur field cat>-decimals_out = 0.
    see this sample code.
    type-pools: slis.
    DATA: begin of itab6 occurs 0,
    chk type c,
    a type p decimals 2,
    b type p decimals 2,
    c type c,
    end of itab6.
    data: ls_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
    wa_layout TYPE slis_layout_alv.
    itab6-a = '1.12'.
    itab6-b = '2.25'.
    itab6-c = '+'.
    append itab6.
    append itab6.
    append itab6.
    append itab6.
    ls_fieldcat-fieldname = 'A'.
    ls_fieldcat-seltext_m = 'A'.
    append ls_fieldcat.
    ls_fieldcat-fieldname = 'B'.
    ls_fieldcat-seltext_m = 'B'.
    ls_fieldcat-decimals_out = 0.  "this ll do
    append ls_fieldcat.
    ls_fieldcat-fieldname = 'C'.
    ls_fieldcat-seltext_m = 'C'.
    append ls_fieldcat.
    wa_layout-box_tabname = 'ITAB6'.
    wa_layout-box_fieldname = 'CHK'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = sy-repid
    it_fieldcat = ls_fieldcat[]
    IS_LAYOUT = wa_layout
    TABLES
    t_outtab = itab6[].
    Cheers,
    jose.

  • How to convert a number to FLOAT with 9 decimal values.

    Hi all,
    I need to convert a number like '10.02' to a floating point number with 9 decimal values like '10.022111221'. I think that the right function is TO_BINARY_FLOAT, but how can I obtain 9 decimal values? If I use the following syntax:
    select TO_BINARY_FLOAT(num) from table
    I obtain a floating point values with a variable number of decimal numbers after the ".", instead I need 9 number after ".".
    Regards,
    Maurizio.

    Hi,
    the number I need to select is the result of a product, for example:
    select (Num_A * Num_B) from Table;
    Num_A has 2 decimal numbers, like 12.01 and Num_B could be: 12.111111111.
    Now, Num_A * Num_B = 653.999999994
    but I issue:
    select TO_BINARY_FLOAT(54.00 * 12.111111111) from Table
    I obtain:
    654, a rounded value, but I need 653.999999994.

  • Rounding off to a variable value to 4 decimal values in sap script ouput

    Hi All,
    I have a value getting displayed in sap script output as 235.6789 i want to Round off this variable value to 4 decimal values!
    What is the formatting option need to be used & how!
    Thanks in advance.
    Thanks,
    Deep.

    Hi,
    1.In layout just call that variable, where you need like:
    &variable(.4)&.
    Just see these:
    &symbol(Z)&  Omit Leading Zeros 
    &symbol(S)&  Omit Leading Sign 
    &symbol(<)&  Display Leading Sign to the Left 
    &symbol(>)&  Display Leading Sign to the Right 
    &symbol(C)&  Compress Spaces 
    &symbol(.N)&  Display upto N decimal places 
    &symbol(T)&  Omit thousands separator 
    &symbol(R)&  Right justified 
    &symbol(I)&  Suppress output of the initial value
    Regards,
    If helpful reward with points(Don't forget).

  • Loading decimal  value to an infoobject of type char

    I have an extract structure with field timestamp, which is of type dec and length 15. Now i want to load this value to an infoobject in ODS. But this infoobject is of type char and length 18. when infopackage loading is scheduled it is giving the following error. Record 1 :InfoObject /BIC/IFITMSTMP does not contain alpa-conforming value 20061206084944.
    Is it because i tried to move a dec valu into a char field with a different length? If so  how will i load a decimal value of length 15 to a char of length 18. Can anyone please help me with this?
    Thanks in advance.

    if u r using BI7.0
    go to the datasource of the cube
    in the general info tab of the datasource
    there is a check box with PSA not typed
    check it
    if u check it all the values from the external source will be converted into character format irrespective of their data type

  • Loading a decimal value to an infoobject of type char

    I have an extract structure with field timestamp, which is of type dec and length 15. Now i want to load this value to an infoobject in ODS. But this infoobject is of type char and length 18. when infopackage loading is scheduled it is giving the following error. Record 1 :InfoObject /BIC/IFITMSTMP does not contain alpa-conforming value 20061206084944.
    Is it because i tried to move a dec valu into a char field with a different length? If so  how will i load a decimal value of length 15 to a char of length 18. Can anyone please help me with this?
    Thanks in advance.

    if u r using BI7.0
    go to the datasource of the cube
    in the general info tab of the datasource
    there is a check box with PSA not typed
    check it
    if u check it all the values from the external source will be converted into character format irrespective of their data type

  • Decimal values are not flowing to Excise Invoice created in J1IIN

    Dear Sap Gurus,
    Please help me with the problem. After creation of invoice in VF01 when i am creaing outgoing excise invoice decimal values for BED, ECS and SEC. ECess( AT1) are not coming instead values are rounded of to nearest whole number.
    for ex.
    if invoice values are as below
    BED= 16
    ECS= 3.2
    HSC= 1.6
    when excise iinvoice is created values are changes as below
    BED= 16
    ECS= 3
    HSC= 2
    please give propeer solution
    reg.
    suresh

    Check in Logistics - General -> Tax on Goods Movements -> India -> Basic Settings -> Maintain Company Code Settings. 
    Also ensure that in V/06, for the respective excise condition types, rounding is not activated.
    thanks
    G. Lakshmipathi

Maybe you are looking for

  • Need to submit custom report when email option chkd and po approved

    Hi All, We use R12, our requirment is to submit a custom report when PO is approved. Not in all cases we need this. when user select 'Approve' option for a Manually created PO, and in the Approval form, when the User selects 'Email' check box and app

  • How do I export video from LR to iPhoto?

    What I'm trying to do is make an imovie. I figured that the easiest way to do this was to export my videos from LR to iPhoto, but can't figure out how to do this. I downloaded the iPhoto publish service, but when I tried it, it said that it didn't su

  • How do I insert a nav bar I made in photoshop into dreamweaver?

    I have spent days making a roll-over navigation bar in photoshop and saved for web with slices, but however I try to insert it into my webpages, (either as a library item or otherwise - not that I really know what I'm doing!) It is always a greyed ou

  • Wired Guest in 5.x 4402 - Does it Work???

    Anyone get Wired Guest access working using the latest code 5.148 (or any code for that matter). In particular has anyone been sucessful using 1 WLC with ingress and egress on same controller. I have been trying for a week and does not work no matter

  • Cisco ISE - multiple AD - trust relationships

    Hello, I have a customer who has multple AD forests and an ISE deployment running 1.1.3. The customer scenario is as follows - there is an Internal AD forest (internal users) and an External AD forest (external users such as consultants). The objecti