how to print -314% in home page using pi value=3.14 in slightly | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Mohit_KBansal

@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 

3 replies

Level 2
August 2, 2022

Hi @vinuu123 

 

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

 

Mohit_KBansal
Adobe Employee
Mohit_KBansalAdobe EmployeeAccepted solution
Adobe Employee
August 2, 2022

@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 

Shiv_Prakash_Patel
Community Advisor
Community Advisor
August 2, 2022

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-of-sightly 

Hope this could help you !!!

Regards

Shiv

 

Shiv Prakash