I need to format a decimal value to a text value, with the currect numbers of decimalplaces. Take this forexamble: message(’%1’, FORMAT(1.90)); shows the text value ‘1.9’ - but it must show the value ‘1.90’ instead. Can the FORMAT function take som parameter, telling it must show the string value with 2 decimalplaces ? - or must I manipulate the text string afterwards…

Try FORMAT(MyValue,0,’<Decimals,3>’)

quote:

Kristensen wrote:I need to format a decimal value to a text value, with the currect numbers of decimalplaces. Take this forexamble: message(’%1’, FORMAT(1.90)); shows the text value ‘1.9’ - but it must show the value ‘1.90’ instead. Can the FORMAT function take som parameter, telling it must show the string value with 2 decimalplaces ? - or must I manipulate the text string afterwards…

If you just press F1 when in designer, you will have available a marvellous help for all commands, where it explains the format command. It will also show you a link to the different format values for the parameter… In the previous example, just using FORMAT(Myvalue,0,’<Precision,2:2><Standard Format,0>’) Please… try using also the standard Navision help… trying to press F1 and searching the help will make you loosing less time than waiting for an answer. From Navision help (just pressing F1):

quote:

FORMAT String := FORMAT(Value [, Length] [, FormatNumber | FormatString]) String Data type: text or code This string contains the formatted output. Value Data type: any This is a C/AL variable (expression) of any simple data type, such as option, integer, decimal, char, text, code, date, time, boolean, or binary. If, when the system formats Value, the result is a value larger than the maximum length MAXSTRLEN of String, a run-time error occurs. Length Data type: integer Use this optional argument to determine the length of String. These rules apply: If Length… It means… Equals zero (0) The system will return the entire value (default) Is greater than zero (0) String will be exactly Length characters. If Value is less than Length characters, the system inserts either leading or trailing spaces, depending on the format you select. If Value is an integer which exceeds Length digits, the system places Length asterisks in String.If Value is not an integer and it exceeds Length characters, the system truncates String accordingly. Is less than zero (0) String will have the maximum length of Length characters.If Value is less than Length characters, the length of String will equal the length of Value.If Value is an integer which exceeds Length digits, the system places Length asterisks in String.If Value is not an integer and it exceeds Length characters, the system truncates String accordingly. FormatNumber Data type: integer Use this optional argument to determine the format you want the system to use. Here is a list of the basic options. The example below explains all available formats: To use this format… Select… Standard Display Format (the default for all data types) 0 Standard Display Format 2 (edit) 1 C/AL Code Constant Format 2 FormatString Date type: string A literal string that defines a format as in the Format property. Note: You can only use one of FormatNumber and FormatString at a time.

[quote]

FORMAT: Use this property to define how the system formats the source expression. Applies to Text boxes, dataport fields Comments The Format property can be set to a predefined format, or you can build a format of your own. See also the FORMAT function. Basic Settings The syntax for choosing a predefined format is <Standard Format,X> , where X is the entry in the Select… column of the table. To use this format… Select… Standard Display Format (the default for all data types) 0 Standard Display Format 2 (edit) 1 C/AL Code Constant Format 2 Note that the brackets (< and >) must be entered, as in <Standard Format,2>. See below for a comprehensive list of available predefined formats and what they mean. Building Formats The Format property also lets you create your own formats. To create a format, use the syntax described below and keep in mind these rules: · A format property consists of zero or more Chars, Fields or Attributes. · Fields and Attributes are expressed with an identifier inside brackets (<>). · Attributes require a comma (,) and a parameter after the identifier. · Fields optionally take a comma (,) and a FieldLen. The concise syntax is: FormatProperty := [ | | ] := character with ASCII value [32…255] := ‘<’ [’,’ ] ‘>’ [, ] := literal name of field (format component) := length of field (0 or missing means that length is dynamic) := [’<’ ‘,’ ‘>’] := [Standard Format | Filler | 1000Character | Comma | Overflow | Filler Character | Precision] The FieldName is a “component” that can be used to build a format expression. Depending on the data type of the text box or dataport field, FieldName can be chosen from this list: Data Type FieldNames Decimal Sign,Integer,Decimals,Integer Thousand Date Day,Month,Month Text,Quarter,Year,Year4,Week, Week Year,Week Year4,Weekday,Weekday Text,Closing Time Hours24,Hours12,Minutes,Seconds,Thousandths,AM/PM, Second dec. Integer Sign,Integer,Integer Thousand Boolean Text,Number Option Text,Number Code Text Char Char/Number,Char,Number Text Text Examples This is some examples of how to use Format. Choosing a standard format: You select one of the standard formats (see below for details), by using the Standard Format attribute. <Standard Format,5> will select Standard Format 5. Using a standard format with an attribute: <Precision,2:><Standard Format,0> will use standard format 0 and will format the data with 2 or more decimal places. See also the DecimalPlaces property. Building a Format You can create your own formats by using Chars (which will be displayed literally), Fields (to choose specific components of a value, for example the year-part of a date) and Attributes (for example to select which character to use as a filler). For a text box based on a source expression of the Date data type, this format string , would print the date like this: Monday, April 15 In the list of predefined formats below, you can see many examples of how to build formats. The Standard Formats The tables below show the predefined formats for each data type. Decimal Format 0 1 <1000Character,.> 2 <Sign,1> 3 <Sign,1> 4 …

[quote]

Alfonso Pertierra (Spain)apertierra@teleline.es

I have decimal = 324.6380

but i want to show as 324.6400

if I have decimal = 324.64

i also want to show as 324.6400

how to set the format???

Look into the ROUND function. That will return a decimal which you can then format to the correct number of decimal places.

Representing the number 324.6380 as 324.6400 is mathematically incorrect, those are two different numbers. If you use 4 decimals, you imply that the number is rounded to 4 decimals.

Not probably.

When you round a Real Number it will obviously returns a different number based on the rounding factor…

The zero after decimal has no value so you are tyring to round 324.638 to 324.64 it can be done - just you need to round off it for two decimals.

The number 324.6380 is a number rounded to 4 decimals, it might have been 324.6380489653214578 to start out with. The number 324.6400 is also a number rounded off to 4 decimals, it might have been 324.640023154689 before it was rounded.

If you want to round 324.6380 to 2 decimals, then you should write that down as 324.64. 324.64 and 324.6400 are two different numbers, because the first one is precise to 2 decimals, and the second one is precise to 4 decimals. 324.6380 and 324.6400 are two completely different numbers altogether.

Representing 324.64 as 324.6400 is simply incorrect. If you display 324.6400 people can safely assume that the number was rounded to 4 decimals, and that is just not the case here. With thousands or millions of transactions could result in a very large financial difference. If the OP wants to round to 2 decimals, then he should display 2 decimals.

The zero after decimal has no value

That is definitely a false statement, and shows that you don’t really understand the number 0. It DOES have a value, it has the value 0, and if it is the last decimal that means that it was rounded to that many decimals, that the number has that much precision.

you are tyring to round 324.638 to 324.64 it can be done

Yes that is correct. When you round 324.638 to 2 decimals, it becomes 324.64. The number 324.6400 however is rounded off to 4 decimals, not 2. Putting those zeros at the end makes it a different number.

Representing 324.64 as 324.6400 is simply incorrect. If you display 324.6400 people can safely assume that the number was rounded to 4 decimals, and that is just not the case here. With thousands or millions of transactions could result in a very large financial difference. If the OP wants to round to 2 decimals, then he should display 2 decimals.

Rounding a number to 2 or 3 or 4 - really a company decision.

Representing the number 324.6380 as 324.6400 is mathematically incorrect

Not probably

I don’t think there is some mathematical rule which governs it. Let me know if there is any such kind of mathematical rule[:)]

324.64 and 324.6400 are two different numbers, because the first one is precise to 2 decimals

No. Its how you are showing the number.

shows that you don’t really understand the number 0.

I don’t think so[:D]

The number 324.6400 however is rounded off to 4 decimals, not 2. Putting those zeros at the end makes it a different number.

not probably true. Rounding will not consider the zero’s.

Kranthi,

Denster is right and you probably don’t understand the concept of **“No. of Significant Figures”**.

the number 324.6380 as 324.6400 is mathematically incorrect

The above is a very valid statement, the original number 324.6380 itself has 4 decimal places and the new number used 324.6400 also has same number of decimal places and they are not equal, so you can’t use this approximation or whatever you call it.

Edit: When you say 324.6400, it means it can’t be 324.6401 or 324.6399 but it can be

324.6400111111111 to 324.6400999999999

Rounding a number to 2 or 3 or 4 - really a company decision.

Yes it is. If they want to round to 2 decimals, they should be displayed with 2 decimals, not 4. If they want to display 4 decimals, they should also round to 4 decimals. Rounding to 2 decimals but then displaying numbers with 4 decimals is just not correct. It goes against very basic mathematical principles, and if I were a tax auditor I would make a very big deal about this.

Look Kranthi, you clearly do not understand the concept the precision that is represented by the number of decimals. If this were just you I would not take the time to set you straight, because you don’t seem willing to listen anyway (I noticed that in other topics as well). But you are giving other people very bad advice, so I need to step in here.

There are about 100 numbers with 4 decimals that round to 2 decimals. 324.64 can be any number between 324.6350 and 324.6449. The first number is rounded to 2 decimals, the latter numbers are rounded to 4. The number 324.6400 is one and only one number with 4 decimals. When you round the number 324.6400 to 2 decimals you get 324.64, but those two numbers are NOT the same numbers. It just does not work both ways. You simply cannot represent the number 324.64 as 324.6400 because the number with 4 decimals implies a precision that it does not have.

Hi Denster,

I have just started a sportive argument - In that my explanation may or may not be correct or you did understood in a different way.

you don’t seem willing to listen anyway (I noticed that in other topics as well)

You completely mis understood me - I will definitely listen if your argument is correct.

But you are giving other people very bad advice, so I need to step in here.

Sorry - can you spot some thing where i have given bad advice to the people.

I have just started a sportive argument - In that my explanation may or may not be correct

You have to understand that many very junior people come to these forums for serious advice, and they take anything they see here posted by ‘experienced people’ as the truth, without really questioning the source. When you start telling them things that you either don’t understand, or you joke about without marking it as a joke, or intend for it to be a “sportive argument”, and I know for a fact that the information that you give is incorrect, I guess I am one of those people that do not understand the humor in that.

I guess I am one of those people that take precision seriously, and that don’t find it humorous when people take that lightly. I can see how you might have intended a certain level of sarcasm in your initial post, but when you started contradicting me I did not (and still don’t) see how you meant that as a joke or something. If you meant your contradictions as a joke let’s leave it at me misunderstanding your intentions, but my arguments in this discussion are correct.

Then let’s leave it. [:)] I think you have used a word that i am giving a bad advice to the people, which is irrelevant and not correct.

Here I have started an argument with you and not given any advice to the fellow members of the forum.[:)]

Thanks any way…

Sure you did:

The zero after decimal has no value

I don’t think there is some mathematical rule which governs it

Rounding will not consider the zero’s

Then you denied that 324.64 and 324.6400 are two different numbers:

No. Its how you are showing the number

It doesn’t look like you meant any of that as a joke, and it’s all incorrect. It is propagating YOUR misunderstandings onto other people, so in my book that’s all bad advice.