Format percentage to the single digit after the decimal - d3.js

There is a number like this:
77.18%
It should be displayed like this:
77.2%
I have formatting using:
.4s , .3s, .1% and few other formats which didn't make any change to the format.
Right now the adaptive formatting in Apache superset is giving 2 digits after the decimal, what should be the number format in order to display percentage number with 1 digit after the decimal?

With d3.js, d3.format(".1%")(0.7718) will return 77.2%.
You have to give a decimal number in input to the formatter.

Related

How to create a GS1-128 barcode using ZPL

Please help with the following situation:
Using ZPL script, I have to generate a barcode with GS1-128 (formally known as Code 128). I have the following specs:
The ideal way to label products is with complex barcodes with delimiters (cf. the GS1 standard, on the GS1-128 barcode model).
The following information is contained in the same barcode:
2. SSCC (only for pallet label);
3. EAN code;
4. Quantity;
5. Expiration date;
6. Lot.
LABEL STRUCTURE EAN 128
(00) - 18 numeric characters
Example: 712300000000125672 - SSCC - Unique pallet code;
(01) / (02) - 14 numeric characters
Example: 02911225000004 - EAN article (includes control key);
(3100) - 6 numeric characters, weight in kilograms without decimals
Example: (3100)000700 represents 700 KG.
(3101) - 6 numeric characters, weight in kilograms with a decimal
Example: (3101)000700 represents 70.0 KG.
(3102) - 6 numeric characters, weight in kilograms to two decimal places
Example: (3102)000700 represents 7.00 KG.
(3103) – 6 numeric characters, weight in kilograms to three decimal
Example: (3103)000700 represents 0.700 KG.
(37) - numeric characters, variable length up to 8 characters - number of packages / pallet.
(17) - 6 numeric characters
Example: 210730 - Expiry date in AALLZZ format
(10) - alphanumeric characters, variable length up to 20 characters
Example: 3245AB / 60 - Lot.CODE.
In order for the system to read the information in the barcode correctly, it can be created in two ways:
The first way is by placing all fields with variable length at the end of the barcode ((37) and (10)) without the need to insert a GS128 separator in the label.
EXAMPLE:
PALLET CODE (SSCC) must always be created separately on the pallet label.
SSCC code:
How it looks scanned:
A second way to create these labels is by inserting the GS128 separator after completing the variable length fields ((37) (10)) when they are inside the barcode.
PALLET CODE (SSCC) must always be created separately on the pallet label.
Example of pallet label with GS128 separator.
It looks scanned like this:
Last part of code:
Looks scanned like:
Thank you very much.

In angular 2, how to display a number as two decimal rounded currency?

Examples:
1.99 --> $1.99
1.9 --> $1.90
1 --> $1.00
1.005 --> $1.01
1.004 --> $1.00
I am using {{num | currency:'USD':true}} but it does not show trailing 0s.
Use this code. Here is a working example http://plnkr.co/edit/xnN1HnJtTel6WA24GttR?p=preview
{{num | currency:'USD':true:'1.2-2'}}
Explanation :
number_expression | number[:digitInfo]
Finally we get a decimal number as text. Find the description.
number_expression: An angular expression that will give output a number.
number : A pipe keyword that is used with pipe operator.
digitInfo : It defines number format.
Now we will understand how to use digitInfo. The syntax for digitInfo is as follows.
{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
Find the description.
minIntegerDigits : Minimum number of integer digits. Default is 1. (in our case 1)
minFractionDigits : Minimum number of fraction digits. Default is 0. (in our case 2)
maxFractionDigits : Maximum number of fraction digits. Default is 3. (in our case 2)
well you got the correct answer but still i think i can elaborate more this answer so posting it as answer:
First of all there are number of pipes available of the angular2 to use in our project some of them are listed below
CurrencyPipe , DatePipe, UpperCasePipe, LowerCasePipe, and PercentPipe and many more.
Here as your question you have problem related to currency pipe. so i want to explain bit more as other answers.
CurrencyPipe :
A pipe may accept any number of optional parameters to fine-tune its output. We add parameters to a pipe by following the pipe name with a colon ( : ) and then the parameter value (e.g., currency:'EUR'). If our pipe accepts multiple parameters, we separate the values with colons (e.g. slice:1:5).
{{number | currency:'your_type':true:'1.2-2'}}
here...first parameter is currency type which is either EUR,USD or anything, Second parameter is true/false for the symbolDisplay which is false byDefault. then Third one is range limit basically a range limit . You can set a min and max length after the decimal point and a fixed number (or leave it blank for default) for the places before the decimal point.
I have found some good tutorials for the pipes in the angular2 which i am posting here..
http://voidcanvas.com/angular-2-pipes-filters/
https://angular.io/docs/ts/latest/guide/pipes.html
Hope it Helps and clarify more about pipes !!
#Pardeep !!
You are using the correct pipe. You just need to add the digit info to the output.
{{num | currency:'USD':true}} should be...
{{num | currency:'USD':true:'1.2-2'}}
For reference: 'USD' represents the type of currency, true represents whether to show the currency symbol ($), and '1.2-2' represents the digit info.
The digit info is {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}.
minIntegerDigits is the minimum number of integer digits to use and defaults to 1.
minFractionDigits is the minimum number of digits after fraction and defaults to 0.
maxFractionDigits is the maximum number of digits after fraction and defaults to 3.
Source for the digit info can be found here: https://angular.io/docs/ts/latest/api/common/index/DecimalPipe-pipe.html
If, like me, you're trying to do this in the typescript/javascript rather than HTML, you can also use toLocaleString
So to convert a number to a currency string:
ppCurrency(number) {
return number.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
Following will convert with 2 decimal digits
{{num | currency : '$' : 2}}
angular 2
{{num | currency:'USD':true:'1.2-2'}}
<input type="number" [(ngModel)]="myModel" (keyup)="onBlurMethod()">
<br>
<br> The formatted currency is :
<br> {{myModel | currency:'USD':true:'1.2-2' }}
Here is the working example.
http://plnkr.co/edit/pSK8p7u3oo4WsAB9aFBS?p=preview
If any body gets a warning and wanted to resolve it, please find below the fix I used.
Following is the warning Angular displays in browser console:
Warning: the currency pipe has been changed in Angular v5. The
symbolDisplay option (third parameter) is now a string instead of a
boolean. The accepted values are "code", "symbol" or "symbol-narrow".
The format that causes the warning: currency: "USD":true:"1.2-2"
Fix: currency: "USD":'symbol':"1.2-2"
Reference: https://angular.io/api/common/CurrencyPipe

Trailing zeroes in a format string?

I have figures representing monetary amounts coming in -- 45.10, 24.35, 17.99, and so on.
I want to split these into the dollar and cent portions, do something to the dollars, and then output a string of dollars + '.' + cents.
PROBLEM: The figure .10 obviously becomes 1, and I don't want to output $84.1. I want $84.10. So the format string should specify "two-digit integer, with a trailing zero if there's only one digit."
Any search I do just turns up results for leading zeroes. Is this possible?
You need sprintf:
sprintf("%d.%02d", dollars, cents) # must be numbers

How to transform String to decimal with two fractional digits in IIB

I'm working on a mapping in IBM Integration Bus and I want to transform a field string from DFDL format to decimal with two fractional digits. But I want the two fractional digits to appear even if they are zero.
For example:
My String on the DFDL: 0058700
Expected result: 587.00
I tried the following xpath code
($valor cast as xs:decimal?) div 100
but it didn't work, it didn't show the two decimal digits
(ie: 587)
I Also tried defining a simple type with a pattern:
<simpleType name="D10">
<restriction base="decimal">
<totalDigits value="10"/>
<fractionDigits value="2"/>
<pattern value="[0-9]{1,12}[.][0-9]{2}"/>
</restriction>
</simpleType>
If your string in the DFDL-described format is '0058700' but its logical value is actually '587.00' then you need to use the dfdl:textNumberPattern property to tell DFDL that is the case. A pattern of "####0V00" should do the trick. The 'V' indicates the position of the (virtual) decimal point.

C# Decimal Format 123.123,44 with Rounding

I need correct sample of using decimal format and decimal rounding to closest integer.
Sample1: I have number 123.345,51 result need to be 123.346,00
Sample2: I have number 123.345,49 result need to be 123.345,00
I found samples but they all use format with comma first 123,345.00 I need in first place point like 123.345,00
Tried with culture info but did not success ..
Sample code:
var amount = 123.345,77;
var cultureInfo = CultureInfo.GetCultureInfo("da-DK");
var formattedAmount = String.Format(cultureInfo, "{0:C}", amount);
When I need to convert formattedAmount to decimal its breaks... I am converting for Rounding values after ,
Solution is to enable users to input in format they want, like 123123,55 then use .Replace(",", ".") to replace , colon character with dot, after that made Decimal.Round and all problem are solved!

Resources