Always display two digits after decimal separator navision - report

I'm using Microsoft Navision 2009. I'm creating report that includes several number with decimal separator (double/float number in C#).
I'm stuck at the point where I want to display every number with two digits after decimal point.
Ex:
if number is 100, I want to display 100.00
if number is 100.5, I want to display 100.50
if number is 100.55, I want to display 100.55
if number is 100.505; i want to display either 100.51 or 100.50
Thank you in advance;
Language that I'm using is C/AL

Don't be lazy. Read essential manuals. Format function is your best friend in Nav.
strsubstno(text01,format(100.10,0,'<Precision,2:2><Standard Format,0>'))
Third argument of Format is actually the format of result text. <Precision,2:3> means that if first argument is decimal it will have from 2 to 3 (minimum 2 and maximum 3) digits in decimal part. <Standard Format,0> means that the rest of format will be standard.
More here!

Related

How to stop Wit.ai from classifying 4 digit numbers as datetime entities?

In my wit.ai application, I sometimes have 4 digits numbers that are used in a way like citations: 1029 B 4930, and I need to label them as such.
Instead wit.ai labels them as "datetime" and I can see why.
I also do need recognition of real datetimes in my application at times, which might make this a more difficult issue.
Is there a way to prevent wit.ai from labelling 4 digit numbers as dates in certain contexts?

Cognos cut off decimal point

In my data set there is a field that is currently a character field and I need to convert it to a numeric one. the problem is not only are there '%' signs hard coded in the data but there are decimal points in there as well and places after the decimal points is not consistent. AKA...
42.01%
8.1%
22%
.05%
I substringed off the % sign but is there a way to just cut the decimal point off and everything after it so then I can just cast it as an integer?
thanks all
Cut % then convert to double. Then apply ceiling function.
What I had to do was put leading 0's on the front of the element because cognos was not reading the entries that started with decimal places. then I had to substring the % off and trim and then cast as a number.

Is dBase file according to specifications

Please consider a DBF file with a field N(7,3). Is it allowed to store 9999.99 in such a field? In my mind 999.999 is the largest number allowed and -99.999 is the smallest.
You are correct on your 999.999. The full amount allows for 3 whole digits (or - plus 2 digits) decimal for 4th position and 3 more actual decimal.

Weird behaviour on Numeric Stepper decimals

I am making an editor for a field with numbers. I tried a text field, but since it's a Number datatype coming in, it didn't go smoothly -- despite recasting strings as numbers etc.. it kept giving me NaN as the value. So I decided it would be best to go with a numeric stepper.
When I initially loaded it up it would drop all my decimals and only display my numbers as integers. I changed the stepIncrement to 0.1 and now it does show the decimals (a weird requirement imo).. but when I step up it occasionally gives me a value like '17.700000000000003' when I would expect 17.7. All of the numbers in my data have a single decimal place. I know I can write a dataformatter, but it seems like it shouldn't be necessary in this situation.
Is there another way I could deal with this?
You've stumbled upon the compromise of trying to represent decimal numbers in floating point binary formats like IEEE 754. Not all decimal numbers can be exactly represented. You can read up on this issue in great detail here:
http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding
You can use Number.toFixed(fractionDigits:uint) to display to an arbitrary number of decimal places.
You can use the valueFormatFunction which takes the numeric value and formats it to a string. You will need to set explicit widths on your numeric steppers to make they fit though.
in your MXML
<s:NumericStepper valueFormatFunction="stepperFormatter"/>
in your script
protected function stepperFormatter(newValue:Number):String
{
return Math.ceil(newValue).toString()
}

Convert number into words using flex

I am trying to convert an entry using a numeric stepper in flex into words to display in a textarea.
i.e a user uses the stepper to enter "89" as a value and in the text area the words "Eighty nine" are displayed.
After much searching i haven't found anything that helps - a few javascript functions but that is all.
any help sample code would be much appreciated.
thanks in advance.
I would suggest you make a hash table with the numbers "0" to "99" as indices (enclosed in quotes) and the values being the word names for those numbers. That will make localization possible without out a lot of complicated code to determine, for example, the difference between "eleven" and "juu ichi" (ten one) in Japanese or between "ninety-nine" and "quatre vingt dix neuf" (eighty-nineteen) in French, "twenty-two" and "zwei und zwanzig" (two and twenty) in German, etc.
Let's name that hash table myNumberWords. Then you would simply convert your digits as follows:
function getWordsFromNumber(num:Number) : String {
return myNumberWords[num.toString()];
}
If you want to go higher than 99, add a hash for the words hundred, thousand, million, billion, etc., then split your whole number into an array and place the appropriate units after every 3rd number, counting from the top of the stack. You'll also have to have zero values and double-zero values counted as empty strings ("") except when there is only one digit and it is a zero, etc.

Resources