Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

how to print -314% in home page using pi value=3.14 in slightly

Avatar

Level 4
 
1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

@vinuu123 Use HTL Number format [1], documentation says:

The formatting pattern supports both a positive and negative pattern, separated by semicolon. Each sub-pattern can have a prefix, a numeric part and a suffix. The negative sub-pattern can only change the prefix or/and suffix. The following characters are supported, at minimum:

  • 0 - digit, shows as 0 if absent
  • # - digit, does not show if absent
  • . - decimal separator
  • - - minus sign
  • , - grouping separator
  • E - separator between mantissa and exponent
  • ; - sub-pattern boundary
  • % - multiply by 100 and show as percentage

Characters can be escaped in prefix or suffix using single quotes. Single quotes are escaped as two in a row.

Examples:

${'#,###.00' @ format=1000}
${'#.###;-#.###' @ format=obj.number}
${'#.00;(#.00)' @ format=obj.number}
${'#.000E00' @ format=obj.number}
${'#%' @ format=obj.number}
${ 'curr #,###.##' @ format=1000.14, locale='de_CH', i18n}

will generate the following output if obj.number evaluates to -3.14:

1,000.00
-3.14
(3.14)
-.314E01
-314%
CHF 1'000.14 <!--/* assuming the formatter 'curr #,###.##' will be translated to 'CHF #,###.##' for the 'de_CH' locale by i18n */-->

[1] https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md 

View solution in original post

3 Replies

Avatar

Level 3

Hi @vinuu123 

 

It can be written as {#% @format=piValue}. For more details you can go through this HTL Specs .

 

Avatar

Correct answer by
Employee Advisor

@vinuu123 Use HTL Number format [1], documentation says:

The formatting pattern supports both a positive and negative pattern, separated by semicolon. Each sub-pattern can have a prefix, a numeric part and a suffix. The negative sub-pattern can only change the prefix or/and suffix. The following characters are supported, at minimum:

  • 0 - digit, shows as 0 if absent
  • # - digit, does not show if absent
  • . - decimal separator
  • - - minus sign
  • , - grouping separator
  • E - separator between mantissa and exponent
  • ; - sub-pattern boundary
  • % - multiply by 100 and show as percentage

Characters can be escaped in prefix or suffix using single quotes. Single quotes are escaped as two in a row.

Examples:

${'#,###.00' @ format=1000}
${'#.###;-#.###' @ format=obj.number}
${'#.00;(#.00)' @ format=obj.number}
${'#.000E00' @ format=obj.number}
${'#%' @ format=obj.number}
${ 'curr #,###.##' @ format=1000.14, locale='de_CH', i18n}

will generate the following output if obj.number evaluates to -3.14:

1,000.00
-3.14
(3.14)
-.314E01
-314%
CHF 1'000.14 <!--/* assuming the formatter 'curr #,###.##' will be translated to 'CHF #,###.##' for the 'de_CH' locale by i18n */-->

[1] https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md 

Avatar

Community Advisor

Hi @vinuu123 ,

Arithmetic Operation is not possible in Sightly, You have to handle this from the backend using Java or JavaScript API.

As Suggested by @Mohit_KBansal , You can use a format pattern to show the percentage and fetching value from the backend.

Please refer to the below useful links:

https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#1223-numbers 

https://stackoverflow.com/questions/30366683/how-to-total-up-first-few-elements-in-a-for-each-loop-o... 

Hope this could help you !!!

Regards

Shiv

 

Shiv Prakash