How to format decimal places in Aspose.Word Template? - aspose.words

I want all numerical data to be formatted with 2 decimal places.
Is there a way to set this in the template word file (where I output the variable value via
<<[variableName] >>
), or even globally?

To format a numeric expression result, you can specify a format string as an element of the corresponding expression tag.
<<[variableName]:"0.##">>
See the following article for more information:
https://docs.aspose.com/words/net/outputting-expression-results/

Related

Regular expression for validating file input string

I have an text file with below input, I need to validate the input in ruby whether it is correct format or not?
Need to read an each line of text file and validate that whether the input is matching to Integer,s1-integer,s2-integer,s3-integer,s4-integer format other wise I need to raise an error that file input format is mismatch.
The input line is not limited to 5, it can be any number of lines.
Integer,s1-integer,s2-integer,s3-integer,s4-integer
Example inputs:
1,S1­-88,S2­-53,S3­-69,S4­-64
2,S1­-92,S2­-86,S3­-93,S4­-77
3,S1­-53,S2­-59,S3­-72,S4­-59
4,S1­-60,S2­-52,S3­-85,S4­-62
5,S1­-85,S2­-53,S3­-74,S4­-61
If I understand you right, you need to validate the following input:
a number followed by four elements with a format ,S1­-85
The following pattern matches the input of that type:
\d(\,S\d\-\d\d){4}
\d matches a number
(\,S\d\-\d\d) matches a group of type ,S1­-85
{4} tells to match ,S1­-85 group 4 times

SPSS save decimal number to ASCII

I am trying to save a numeric-with-decimal-places(f8.6) variable from an SPSS file into a fixed ASCII file. The goal is to write it into certain columns of the ASCII (21 to 30).
WRITE OUTFILE='C:\misc\ascii.dat'
ENCODING='UTF8'
TABLE /1
variable 21-30.
exe.
writes to the correct positions, but not with decimals.
variable 21-30 (f)
does the same thing.
variable (f8.6)
saves with decimals, but on positions 1 to 10.
variable 21-30 (f8.6)
results in an error, because apparently you cannot specify both columns and format.
I know two workarounds, but both involve additional data editing, which I'd rather not do:
Convert variable to string and save it as string - but I am not sure about the implications (encoding, decimal places, or whatever other thing I am not even considering)
add an empty string variable with length of 20 before my variable.
But is there a straightforward way of doing this, without workarounds ?
You can add the 20 spaces in the command itself, like this:
WRITE OUTFILE='C:\misc\ascii.dat'
ENCODING='UTF8'
TABLE / ' ' YourNumVar (f8.6) .
exe.

xslt 2.0 remove spaces from string-to-codepoints

I am generating an ID using generate-id(), I convert this ID into a numbers using string-to-codepoints.
How can I remove the spaces from the resulting number?
So e.g. the resulting codepoints are "17 28 39 28", but I need "17283928".
Translate doesn't work, because it expects a string. And I cant convert the number to a string, because string() cannot handle the spaces.
How can I achieve this?
Based on your comment, you used string-to-codepoints(generate-id()) in an attribute value template, in an attribute value template if the expression evaluates to a sequence then a space separated list of values of the sequence is inserted. You either need to use string-join on the sequence to construct a single string or you need to construct the string outside of an attribute value template, as <xsl:value-of select="string-to-codepoints(generate-id())" separator=""/> allows.
Here is an example using string-join:
<xsl:template match="foo">
<bar id="{string-join(for $n in string-to-codepoints(generate-id()) return string($n), '')}" />
</xsl:template>
which will construct a result element alike <bar id="1004910149"/> without spaces in the attribute value.
(Not an answer but too long for a comment).
Interesting supplementary: does this algorithm guarantee unique keys?
Could there be two distinct strings such that the function string-join(string-to-codepoints($x)!string(), '') produces the same string of digits?
I think you're in luck, because generate-id() is guaranteed to produce strings consisting only of ASCII alphanumeric characters. This means that all the characters must have codepoints in the range 48 to 122, which means that every codepoint converts to either 2 or 3 digits, and by looking at the first digit you can tell whether it's a 2-digit or 3-digit sequence.
Before I worked this out, I was going to suggest that you pad the codepoints with zeroes to make all the sequences uniform length.

throwing error when trying to access hashmap with key with a numeric value or special chars

throwing an error when trying to access hashmap with key with a numeric value or special chars
Here is the code I am trying to use:
<div th:include="${myMap[__${dept.code}__]}"/>
If code has letters , this works fine, but if it holds only a numeric value "1234" , this fails .
Appreciate any resolution on this. Thanks..
If the map is based on string keys you shpuld ensure that the precomputed expression is always a string.
A TextLiteral expression can only consist of a limited type of characters. A-z, underscores, minus and some others.
To ensure it's always a string you can wrap the precomputed expression in single quotes:
<div th:include="${myMap['__${dept.code}__']}"/>

Using Format in a livebindings CustomFormat

I'm trying to use LiveBindings to format a number for display in a TEdit on a FireMonkey form.
I'm trying to use the Format method in the CustomFormat of the binding to format the number with two decimal places.
I can 'hard code' the output:
Format("Hello", %s)
which is working, but I can't work out what formatting string to use. If I try a standard formatting string such as,
Format("%.2f", %s)
I get a runtime error "Format invalid or incompatible with argument".
Indeed I get an error whenever I include a % symbol in the format string, so I'm guessing Format takes a different type of argument, but I can't find any documentation to say what the correct format string is.
You can not use Format('%.2f',[%s]) in LiveBindings -> CustomFormat
The %s is reserved for the data and for a TEdit , it's a string
d : double;
s : string;
...
d := 1234.5678;
s:=Format('%.2f',[d]);
Format() is to convert [int, decimal, double, float] to a string .
all other give you a error : invalid argument
valid is for example
TLinkControlToField1 -> CustomFormat : "Double : "+UpperCase(%s)
will give you in Edit1.text
Double : 1234.5678
OK , we know that Uppercase() for '1234.5678' has no effects .
Is only to show (%s) is a string
Solutions:
Set to TFloatField -> DisplayFormat #00000.00
rounds and display 01234.57
check TFloatField -> currency
rounds and display 1234.57
use a component look here
LiveBindings in XE3: Formatting your Fields
The parameter is passed into CustomFormat as %s. The bindings system preparses out this parameter before the data is passed onto the evaluator. Thus any other % symbols in the CustomFormat string will give an error.
As with a normal format string you can include a literal % sign by putting a double % (i.e. %%).
So, any %s in the format string need to be converted to %%, e.g.
Format('%%.2f', %s)
which gets parsed out to
Format('%.2f', 67.66666)
and then parsed down to
67.67
for display.
If you want to include a literal % in the final output you need to put a quadrupal %, e.g.
Format('%%.2f%%%%', %s)
becomes
Format('%.2f%%', 67.6666)
and displays as
67.67%
Note: The normal format function takes a final parameter which is an array of values. The Format method in the bindings system takes a variable length list of parameters.
Also, the method names are case sensitive. 'Format' is correct, 'format' will fail.
imput 67.6666
CUSTOM FORMAT: ToStr(Format('%%.2f', Value)) + ' %%'
output 67.00 %

Resources