Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

Avatar

Level 3
 
1 Accepted Solution

Avatar

Correct answer by
Employee

@Babita11 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 2

Hi @Babita11 

 

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

 

Avatar

Correct answer by
Employee

@Babita11 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

Level 4

Hi @Babita11 ,

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