Number of digits after decimal point.
Hi,
Here is a small program which takes x1 and gives the square root of x1, For e.g for 2 it prints 1.4142135623730951
Suppose I need to have only one decimal place i.e 1.4 then how do I get this.
import java.util.*;
class MySquare {
public static void main(String args[]) {
double x1 = 2;
double x2 = Math.sqrt(x1);
System.out.println("Square root of x1 " + (x2));
Output of this is:
Square root of x1 1.4142135623730951
try:
int whole = (int)x2;
int decimal = ((int)(x2*10)) - whole*10;
System.out.println("Square root of x1 " + whole +"."+decimal);p.s. this is untested, but it gives you an idea
Similar Messages
-
How to get only two digits after decimal point of an expression
i am doing simple multiplication between two float numbers.
both the numbers have two digits after decimal point.
so naturally the result will have 4 digits after decimal point.
i want to get only two digits after decimal point.
help me please...If you just want to limit the displayed decimal places, you can do the following...
import java.text.*;
public class Formatting {
public static void main(String[] args) {
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumFractionDigits(2); //what you seem to want
format.setMinimumFractionDigits(2); //if you always want at least 2 digits displayed
System.out.println(format.format(12.345));
System.out.println(format.format(12.0)); -
Purchase price to have 4 digits after decimal point
Hi Friends,
Would you please help me out with this issue?
The purchase price needs to have 4 digits after the decimal point, because the product/component would be packed and sold in other unit, which may give huge value difference.
The price can be set for the product/component per 100, but is there any setting in SAP Reference IMG?
Thanks for your help.
Regards,
JTHi,
In material Master (MM01) which unit you maintain for that material. Go to MM02 and keep Base Unit of Measure as storing unit as earlier and maintain Sales unit (unit of measure in which the material is sold) or Order Unit (Specifies the unit of measure in which the material is ordered) in the Purchase Order according to your requirement and Enter the factor for converting the alternative unit to the base unit. In your case product/component would be packed in a Different unit.
OR
In your case product/component would be packed in a Different unit.
Maintain the (BOM) Bill of Material for the finished product you are selling and its component.Create Finished Product as material type as FERT and Components as material type as HALB or ROH.
Now try your transaction with Finished Product only and sale.
Hope the above will help.
Regards,
Biju K -
Limit the number of digits after the decimal point
hi,
in webform how to limit the number of digits after the decimal point?
thanksHi,
In the Web form Design menu there is a tab for Other Options wherein you would find the setting for number of Decimal places.
Thanks.
Madhavi -
How to get values after decimal point
Hi,
source value is 12345.678 i wana the target side in 12345 in field and 678 in one field.
the source value its not fixed before decimal point value pass to one field and after decimal point value pass to other field
please help to me how to do this one.Hi Swathip,
You dont need to create 2 UDFs. You just need to create 1 simple UDF which takes one string array as input as usual and it has 2 Resultlist outputs. You need to map this 2 outputs from the UDF to the respective 2 target side fields where the values are to be mapped, one containing the portion before the decimal, and one after the decimal.
I HAVE TESTED THE UDF AND IT WORKS ABSOLUTELY FINE.
THE CODE FOR THE UDF IS AS FOLLOWS:
public void sepDec(String[] num,ResultList wholeNum,ResultList afterDec,Container c)
String part1=null; // Stores the part before the decimal point
String part2=null; //Stores the part after the decimal point
if(num[0]!=null && num[0]!=""){
int index = num[0].indexOf(".");
part1 = num[0].substring(0,index);
part2=num[0].substring(index+1, num[0].length());
wholeNum.addValue(part1);
afterDec.addValue(part2);
THIS UDF IS A CLASSIC EXAMPLE WHERE AN UDF HAS 2 OUTPUTS, WHICH IS VERY RARELY SEEN BUT VERY MUCH CORRECT
PLEASE LET ME KNOW IF THIS CODE WAS HELPFUL TO YOU
CHEERS,
BISWAJIT
Edited by: 007biswa on Feb 8, 2011 5:02 PM -
Process order confirm_Goods movement_Qty consum. after decimal point not al
Sir,
I am doing process order confirmation (COR6), In which go to "Goods Movement "....and consume actual consumption qty...but when i put figure after decimal point, system does not allow...e.g 3.524 KG...System rounded figure which i put in BOM...e.g in bom 3.524 KG, but when i confirm (COR6) the order shows 4 KG....
Pl. help how to put decimal point...
Pl. not that in BOM , system allows to put decimal point qty, but in confirmation it does not allow...
Error message comes :
Only 0 decimal places are permitted for unit of measure KG
Message no. RU303
RajeshSir,
We check in CUNI,
But in BOM, Decimal Point is allowed, but when we confirm the process order decimal place is not allowing...
If seems that is it any setting in process order ?...Because if any error in CUNI then it does not allow at BOM creation level also....
Rajesh Mehta -
How to remove zero after decimal point.
hi friends
how to remove the zero after decimal points.
example :
123.450 -- if print only 123.45
45.600 - 45.6
any body help me.
thanks
pauldhamago through this example
it may help u
DATA: T(14) VALUE ' abcdefghij',
STRING LIKE T,
STR(6) VALUE 'ghijkl'.
STRING = T.
WRITE STRING.
SHIFT STRING LEFT DELETING LEADING SPACE (or use 0 to detete 0).
WRITE / STRING.
STRING = T.
SHIFT STRING RIGHT DELETING TRAILING STR or 0.
WRITE / STRING.
Output:
abcdefghij
abcdefghij
abcdef -
How to enforce position after decimal point
Hi,
i need to enforce a position after the decimal point in an SAPScript Form.
The Form is MEDRUCK_RV and the field ist RM06P-PRMG1.
I tried to enforce it with RM06P-PRMG1(Z9.1) but it doesn't work.
I need to cut the left-hand zeros and display one position after the decimal point.
Can someone help?Hi,
Try this.
DATA : DFORMAT TYPE XUDCPFM,
L TYPE I.
SHIFT RM06P-PRMG1 LEFT DELETING LEADING '0'.
SELECT SINGLE DCPFM FROM USR01
INTO DFORMAT WHERE BNAME = SY-UNAME.
IF SY-SUBRC EQ 0.
IF DFORMAT EQ 'X'.
SEARCH RM06P-PRMG1 FOR '...'.
ELSE.
SEARCH RM06P-PRMG1 FOR ','.
ENDIF.
ENDIF.
IF SY-FDPOS NE 0.
L = SY-FDPOS + 2.
RM06P-PRMG1 = RM06P-PRMG1+0(L).
ENDIF.
Thank You,
Saritha -
Shorting the number of digits after the dot
how do I changing an endless float number (that has alot of digits after the dot) to number with only 2 digits after the dot?
java.text.DecimalFormat.
-
How to count the number of digits before decimal value
Hi I've a decimal value like this
123,456.700000000000
I need output as 6 (because I've 6 digits before decimal)Try
Declare @d decimal(30,9)=123456.700000000000
SELECT FLOOR(@d)
SELECT len(FLOOR(@d))
Thanks
Manish
Please click Mark as Answer if my post solved your problem and click
Vote as Helpful if this post was useful. -
Hi Gurus,
Our client does not the condition values in decimal points in pricing.
They want it to be scaled up always to next round figure.
Eg. 12.25 should be converted to 13.00
Please suggest.
Thanks,
RaheelDear Raheel
For the net value field, you need to give Routine 16 in the Alt. Cal. Type in the pricing procedure and also add Routine 17 to Netvalue in your Pricing Procedure. Additionally, in table T001R such rounding data should be maintained. For this goto SPRO - SAP NetWeaver - General Settings - Currencies - Define rounding rules for currencies here maintain: Company Code + Currency = 100
thanks
G. Lakshmipathi -
Currency tables that stores description of currency after decimal points.
Hi ,
I need table that stores description of currency
for example : for INR its Rupees and paise...
I need table that stores paise,Cents for Dollars etc..
Table TCURC will show Rupees, Dollars...but doesnt show paise,,cents etc..
Thanks in advance
Kashyap.hi,
you can get number of decimals for currency from TCURX table.
To read them in program use SPELL_AMOUNT function module. -
hello friends,
in smartform i have one field which is in currency i have declared it in currency also so output like 40.000,00 but actually 40,000.00 when i have converted it in string it is like 40000 but i need in 40000.00 form so how can i do it.
thanks in advanceHi,
You can use Character Type Variable with length 15 so when you pass this Currency value it would be as your requirement is.
Check this small program.
DATA: output(15).
data: wrbtr type bseg-wrbtr.
SELECT SINGLE wrbtr FROM bseg INTO wrbtr.
output = wrbtr.
condense output.
WRITE output.
Thanks,
Prashanth -
Dynamic displaying of decimal points for currency field in ALV
Hi,
In ALV output there is a currency field and displaying data of different countries. It should display decimal point according to the country's currency. But at a time it can display data of different countries.Hi Dilip,
I think your question is about currencies with different number of digits after decimal point. If you have the currency field in the ALV row, you have to give it's name as currency reference for the value field in the field catalog.
After creating the field catalog, call a form and do something like this (change fielnames accordingly).
<pre>
*& Form alv_fieldcat_enhance
Individual Enrichment of field catalog
FORM alv_fieldcat_enhance
CHANGING pt_alv_fieldcat TYPE slis_t_fieldcat_alv.
FIELD-SYMBOLS:
<alv_fieldcat> TYPE slis_fieldcat_alv.
LOOP AT pt_alv_fieldcat ASSIGNING <alv_fieldcat>.
IF <alv_fieldcat>-fieldname(5) = 'KBETR' OR
<alv_fieldcat>-fieldname(5) = 'SKBTR' OR
<alv_fieldcat>-fieldname(5) = 'DMBTR'.
Company code currency
<alv_fieldcat>-cfieldname = 'BWAER'.
Document Currency for conditions, net value and taxes
ELSEIF <alv_fieldcat>-fieldname(5) = 'KWERT' OR
<alv_fieldcat>-fieldname = 'NETWR' OR
<alv_fieldcat>-fieldname = 'NPAX_MWST_AMNT'.
Document Currency
<alv_fieldcat>-cfieldname = 'WAERK'.
ENDIF." <alv_fieldcat>-fieldname(5) = 'KBETR' or
ENDLOOP." at pt_alv_fieldcat assigning <fieldcat_alv>.
ENDFORM. " alv_fieldcat_enhance
</pre>
Regards,
Clemens -
Rounding off to nearest decimal point
i have these values
35.2
35.3
35.4
35.5
35.7
35.8
35.9
36.0
i am looking for indexes closet 35.74 in my array. (which is index 4.)
i used the "round to nearest" function and it gave me 36.
which is index 7.
what other ways to get the right index?
Solved!
Go to Solution.You will always have some difficulties with rounding to a specific number of digits after the decimal point because of the way numbers are represented in binary. When expressed in binary 0.1 is an infinitely repeating expression. Regardless of the display the internal representation of the number always uses the maximum resolution for the data type (8 bytes for DBL).
So you need to be very careful to define exactly what you want. If you have an array of values (regardless of the way they are displayed) Then you can find the closest to a Test Value by subtracting Test Value from the array and finding the minimum of the absolute values of the differences.
Note that in the image below the same values are in Array and Array 2 with the display on Array 2 set for 20 siginficant digits.
Lynn
Maybe you are looking for
-
My iPad will not print to my wireless hp office jet 6600 anymore
MY iPad will no longer print to my wireless hp office jet 6600 printer
-
Unavaliable items in shopping cart
Before the last iTunes upgrade, I added some songs to my shopping cart. And I upgrade iTunes (from 7.5 to 7.6), accept the new agreement of the iTunes store and go to the shopping cart. It shows me that some items is unavaliable. So I add those unava
-
What can I change to gain access to my work vpn. I can access with my MacBook Air and other routers. Can use my ipad and this time capsule to successfully access the VPN.
-
Can't Back-Up Music! ~ Please Help!
I've always been able to simply highlight my music library files and drag them over to a folder on my external HD but tonight I got this error message when I tried to back-up my music! I tried to close all programs and that didn't work, I then did a
-
I am having problem in executing email output in order.In customer master email address is mentioned correct.But from order when I am executing the email output its going to some the customer email address not the one which is mentioned in the custom