Ab Initio - Formatting a number in Left alignment - number-formatting

I have a requirement in Ab Initio to format a number in left alignment. I shouldn't be using String conversion (as Strings are left aligned by default), as it might cause compatibility problems in the other end.
For example, if my Field has 7 bytes length, and I'm getting only two digits as my input, then these two digits should go into the first two bytes of my field (left aligned), instead of the last two bytes.
So, is there any in-built function in Ab Initio, that can format a number as left aligned?

You can convert it to string and let it ride. Ab Initio will automatically convert between string and decimal. Also, the physical representation will be the same for these two types.
If you are trying to use a non-ascii based format (int, float, etc.) I don't think there is a built-in function for this and you will probably have to do something rough like cast it to a void type then to a string type using hex_to_string() to preserve the exact bits and then right pad with spaces.

Related

How to interpret iTextSharp TJ/TF result

I'm implementing an automation process with PowerShell using iTextSharp lib, to extract needed information about several PDF documents.
Based on this PDF content portion:
It returns this result:
[(1)-1688.21(1)-492.975(0)-493.019(0)]TJ
[(5)-493.019(0)-17728.1(2)]TJ
I can extract the literal values with some regex manipulation but, only using this method the result is:
$line -replace "^\[\(|\)\]TJ$", "" -split "\)\-?\d+\.?\d*\(" -join ""
1000
502
Of course, these results are not integral, and I need more specification on the reading/parsing.
I'm suspecting that the numbers between the literal characters (e.g -1688.21,-492.975,...), may be useful, but I didnt find explanation about such parameters.
What they represent?
When you are wondering about details of the PDF format, you should have a look into the PDF specification ISO 32000.
Operands
Operator
Description
array
TJ
Show one or more text strings, allowing individual glyph positioning. Each element of array shall be either a string or a number. If the element is a string, this operator shall show the string. If it is a number, the operator shall adjust the text position by that amount; that is, it shall translate the text matrix, Tm. The number shall be expressed in thousandths of a unit of text space (see 9.4.4, "Text Space Details"). This amount shall be subtracted from the current horizontal or vertical coordinate, depending on the writing mode. In the default coordinate system, a positive adjustment has the effect of moving the next glyph painted either to the left or down by the given amount. Figure 46 shows an example of the effect of passing offsets to TJ.
(ISO 32000-1, Table 109 – Text-showing operators)
Thus,
I'm suspecting that the numbers between the literal characters (e.g -1688.21,-492.975,...), may be useful, but I didnt find explanation about such parameters.
What they represent?
For each such number, the operator adjusts the text position by that amount. The number is expressed in thousandths of a unit of text space. This amount is subtracted from the current horizontal or vertical coordinate, depending on the writing mode.

Remove commas and decimal places from number field

I am trying to add two zero place holders in front of a field without changing the actual values involved. The field is an order number that is being pulled from MOMs. So right now that fields' formula is {cms.ORDERNO}.
When I try '00'+{cms.ORDERNO} the field displays 001,254.00. How can I remove the decimals and comma so it displays 001254?
The usual trick is to pad with plenty of extra digits on the left and then only take the six you really want from the right. This would handle any order number ranging from 1 to 999999.
right("000000" + totext({cms.ORDERNO}, "0"), 6)
When you don't specify a format string, as you tried, it uses default settings which usually come from Windows. By the way, if I recall correctly cstr() and totext() are equivalent for the most part but totext() has more options.
You should also be able to specify "000000" as the format string to produce the left-padded zeroes. Sadly I don't have Crystal Reports installed or I'd check it out for you to be sure. If this is the case then you probably don't need a formula if you just want to use the formatting options for the field on the canvas. If you do use a formula it's still simple.
totext({cms.ORDERNO}, "000000")
You definitely want to use the Replace formula a few times for this. The formula below converts ORDERNO into string, removes any commas and trailing decimal places, then adds the two zeroes at the beginning:
`00` + REPLACE(REPLACE(CSTR({cms.ORDERNO}),".00",""),",","")
So for example, if cms.ORDERNO is 1,254.00 the output from this formula would be 001254
I know this is older, but better solutions exists and I ran across this same issue. ToText has what you need built right in.
"00" + ToText({cms.ORDERNO}, 0, "")
From the Crystal Documentation:
ToText (x, y, z)
x is a Number or Currency value to be converted into a text string; it
can be a whole or fractional value.
y is a whole number indicating the number of decimal places to carry
the value in x to (This argument is optional.).
z is a single character text string indicating the character to be
used to separate thousands in x. Default is the character specified in
your International or Regional settings control panel. (This argument
is optional.)

Convert two hexadecimal strings into datetime object

I have a hex number (uint32) stored as a character string. The character string is 'DA5CE697'. I want to convert this to a normal hex number on which I can perform some hex arithmetic operations. Are there any functions that can do this in matlab (like str2num for normal numbers)? Or if there is any other way of going about it?
Update
The character string provided above is the first part of an NTP timestamp. I am using:
datetime(t1 + 1/t2, 'ConvertFrom', 'epochtime', 'epoch', '1900-01-01')
To get the exact time from a data file. Both t1 and t2 are 4 bytes. The values for them are:
t1 = 'DA5CE697';
t2 = '7F14FCE7';
Ideally, I could have gone about reading 4 bytes at once and get the values for t1 and t2. But I have to traverse the file 1 byte at a time (some constraints). So, I am stitching back the values for t1 and t2 (to avoid missing zeros. Otherwise, it stores '05' as '5').
Your string is a hexadecimal representation of your uint32 number. If you instead want the integer (decimal) version of your hexadecimal string, you will need to convert it using hex2dec to be able to perform arithmetic within MATLAB.
f = hex2dec('DA5CE697')
%// 3663521431
Alternately, if you want your hexadecimal value to be cast as a floating point number you can instead use hex2num.
MATLAB does not have a hexadecimal datatype so I'm not sure what "hexadecimal arithmetic" you're expecting to be able to perform.
Update
Now that you have provided more information, you will combine t1 and t2 into a time stamp using hex2dec on both of them (as I showed above) and then perform the arithmetic using the decimal values.
t1 = 'DA5CE697';
t2 = '7F14FCE7';
datetime(hex2dec(t1) + 1/hex2dec(t2), 'ConvertFrom', 'epochtime', 'epoch', '1900-01-01')
%// 03-Feb-2016 20:50:31

Maximum length of a string after performing unicode casefolding

I need to perform casefolding on a set of strings, and must ensure beforehand that they will not exceed a given length after this is done (to hard-code the needed buffer size). The problem is that a string length (in code points) may change after casefolding is applied. See, e.g., in Python3:
>>> "süß".casefold()
'süss'
Now, the maximum number of code points a string may contain after performing casefolding can be computed easily:
>>> max(len(chr(s).casefold()) for s in range(0x10FFFF + 1))
3
But is it valid in all cases? I mean, is it possible that the sequence of code points (the order in which they appear) might affect the final length of the string, due to some arcane property of Unicode? Or can I assume that the final string will always be at most 3 times longer than the original?
The Unicode standard defines casefolding as follows:
toCasefold(X): Map each character C in X to Case_Folding(C).
So every character in a string is casefolded regardless of context and the results are concatenated. This means that your assumption is correct: A casefolded string is guaranteed to have at most three times the number of code points of the original.

SSRS graph with optional decimal positions

Is is possible to show optional decimal numbers for the values in the graph? I want to show up to 2 decimal values but only if the user inputs them. If the value is 9.34, I want it to show that. But if the value is just 9, I want it to show just 9. If the users types 9.3 then only that should be shown.
You can accomplish that by converting the decimal value to a string and then using format characters like this:
=Format(CStr(Fields!a.Value),"#.##");
The # character will only diplay if a decimal value exists. ( fyi, if you wanted the opposite from the format string, using 0.00 would force display zero's even if the values were integers ).
You can also use a combination such as 0.## or 0#.##
Further:
You can also just place that format string in the Custom option under Number in properties.