How to get the decimal value alone correctly?
Aravindh_Navision
Member Posts: 258
Hi Friends,
I have a decimal field. I have to seperate the integer part and decimal part seperately and store in string field.
Decimal Field Value: 62134.1818515
The output I expect is:
IntegerPart : 62134
DecimalPart : 18
Note: I need not round this to any position.
Datatype: IntegerPart, DecimalPart - Code[20]
The code I wrote is:
I am getting the output as: 62134**
Thats is IntegerPart : 62134
DecimalPart : **
Why it is so? Can anyone help me on this?
Thanks in advance
Aravindh R.
I have a decimal field. I have to seperate the integer part and decimal part seperately and store in string field.
Decimal Field Value: 62134.1818515
The output I expect is:
IntegerPart : 62134
DecimalPart : 18
Note: I need not round this to any position.
Datatype: IntegerPart, DecimalPart - Code[20]
The code I wrote is:
IntegerPart := FORMAT(DecimalFieldValue,0,'<Integer>'); DecimalPart:= FORMAT(DecimalFieldValue,0,'<Decimals,2>');
I am getting the output as: 62134**
Thats is IntegerPart : 62134
DecimalPart : **
Why it is so? Can anyone help me on this?
Thanks in advance
Aravindh R.
0
Comments
-
-
You can try this:
DecimalPart:= FORMAT(DecimalFieldValue,0,'<Decimals,8>');
DecimalPart := COPYSTR(DecimalPart,2,2);0 -
Hi,
how about this:decimal := 62134.1818515; integerpart := FORMAT(decimal,0,'<Integer>'); decimalpart := COPYSTR(FORMAT(decimal,0,'<Decimals>'),2,STRLEN(FORMAT(decimal,0,'<Decimals>'))); MESSAGE('Int: %1 dec: %2',integerpart,decimalpart);
Will this work for you?
Regards,
WillyFostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.0 -
The decimal part of your number is 8 characters long. Because this does not fit into your given field length of 2, the whole field is filled with *. You need to cut out the needed length afterwards. There is another problem, though. The Decimals part contains the decimal separator as it's first character. I suggest to use
DecimalPart := DELCHR(FORMAT(DecimalFieldValue,3,'<Precision,2:><Decimals><Comma, >'));
The <Precision,2:> part is to assure you get digits and no blanks within your two needed characters (for values of DecimalFieldValue with one or zero digits) This would otherwise lead to probably unexpected results: 3.1 -> '1' (or '1 '); 3.101 -> '10'. If you want to get blanks instead e.g. for 3.1 DecimalPart = '1 ', then you need to leave out that part of the format string and probably change DELCHR to only delete blanks at the beginning of the string and maybe add another DELCHR to delete '0' from the end.0 -
That's why I said ROUND.
Simple solution if you don't have to consider anything else:dec := 62134.1818515; intpart := FORMAT(dec DIV 1); decpart := FORMAT(ROUND(dec) MOD 1 * 100); // OR: decpart := FORMAT((dec MOD 1 * 100) DIV 1);
Complex solution:dec := -62134.188515; intpart := FORMAT(ABS(dec) DIV 1); decpart := FORMAT(ROUND(ABS(dec),0.01,'<') MOD 1 * 100);
Both not tested..."Money is likewise the greatest chance and the greatest scourge of mankind."0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
