{"id":154,"date":"2012-08-27T09:31:40","date_gmt":"2012-08-27T08:31:40","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=154"},"modified":"2012-08-27T09:31:40","modified_gmt":"2012-08-27T08:31:40","slug":"how-to-format-number-with-zero-prefix","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=154","title":{"rendered":"How to format number with zero-prefix"},"content":{"rendered":"<p>Let&#8217;s presume you want to format number to have &#8216;0&#8217; prefix.<!--more--><\/p>\n<p><span style=\"text-decoration: underline;\">Example problem:<\/span><br \/>\nPRICE = 100<br \/>\nRequired output = 00000100<br \/>\n<em>or<\/em><br \/>\nPRICE = -100<br \/>\nRequired output = -0000100<\/p>\n<pre lang=\"abap\">*----------------------------------------------------------------------*\r\n*       CLASS lcl_format DEFINITION\r\n*----------------------------------------------------------------------*\r\n*\r\n*----------------------------------------------------------------------*\r\nclass lcl_format definition.\r\n  public section.\r\n    class-methods:\r\n      format_with_zeros\r\n        importing\r\n          value(i_in) type numeric\r\n       changing\r\n          c_out     type csequence.\r\n  protected section.\r\n  private section.\r\nendclass.                    \"lcl_format DEFINITION\r\n*----------------------------------------------------------------------*\r\n*       CLASS lcl_format IMPLEMENTATION\r\n*----------------------------------------------------------------------*\r\n*\r\n*----------------------------------------------------------------------*\r\nclass lcl_format  implementation.\r\n  method format_with_zeros.\r\n    data: l_width type i.\r\n\r\n    describe field c_out length l_width in character mode.\r\n    if i_in &lt; 0.\r\n      c_out = |-{ abs( i_in ) align = right pad = '0' width = l_width - 1 }|.\r\n    else.\r\n      c_out = |{ i_in align = right pad = '0' width = l_width }|.\r\n    endif.\r\n  endmethod.                    \"format_with_zeros\r\nendclass.                    \"lcl_format IMPLEMENTATION\r\n\r\nstart-of-selection.\r\n  data: l_num type dec10,\r\n        l_out type char10.\r\n\r\n  l_num = 10.\r\n  lcl_format=&gt;format_with_zeros( exporting i_in = l_num changing c_out = l_out ).\r\n  write \/ l_out.\r\n  l_num = -10.\r\n  lcl_format=&gt;format_with_zeros( exporting i_in = l_num changing c_out = l_out ).\r\n  write \/ l_out.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s presume you want to format number to have &#8216;0&#8217; prefix.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,9],"tags":[446,33,35,34,17],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","tag-abap","tag-conversion","tag-format","tag-prefix","tag-sap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-2u","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":3,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/157"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}