How to format a decimal into a string?

nicole
Member Posts: 25
hi!... new to navision here... in C/AL code, how will i format a number with data type of decimal into a string?... the output should be a string and should always have 2 decimal places...
for example: the output of 5 should be 5.00 (in string)
thanks in advance for your help!
for example: the output of 5 should be 5.00 (in string)
thanks in advance for your help!

0
Comments
-
There are internationalization issues here:
-
1) Do you want the 'decimal point' to follow the convention for the user's locale (e.g. someplaces use 'dot', others use 'comma'), or do you always need a 'dot'?
2) Do you want the thousands to be grouped (e.g. 1,234.56), and if so, should the 'grouping symbol' follow the convention for the user's locale, or do you require a specific character?
MyString := FORMAT(MyDecimal);
If this doesn't give you the right number of decimal places, tryMyString := FORMAT(MyDecimal,0,'<Precision,2:2><Standard Format,0>');
If you do not want thousands grouping, use one of the following:MyString := FORMAT(MyDecimal,0,2); MyString := FORMAT(MyDecimal,0,'<Precision,2:2><Standard Format,2>');
Finally (or perhaps better 'first') see the on-line help 'C/SIDE Reference Guide' topic on the Format property and the FORMAT statement.0 -
thanks fb!0
-
I try to round the decimal variable decVariable to exactly one decimal, but it just won't work. I use this syntax:
FORMAT(decVariable,0,'<Precision,1:1><Sign><Integer Thousand><Decimals>')
And I get these results:- 484
- 199.5
- 422
- 1034.50
- 1246.00
As you can see, some numbers are converted to two decimals even when the original number is an integer value. What am I doing wrong?0 -
Hi PaLPiTaTioN,
i have tested your code and at me it works.
how did you test?
br
Josef Metzbr
Josef Metz0 -
It's really odd.
The string output is written to ascii. The thing is that my output is being written to a csv-file which then is read by Excel. I used an hex-editor to doublecheck the contents of the csv-file, and in that file the output is correct. So the Navision-functionality is alright.
Danke!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 320 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