{"id":3753,"date":"2022-11-14T09:25:06","date_gmt":"2022-11-14T09:25:06","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3753"},"modified":"2023-01-25T10:17:07","modified_gmt":"2023-01-25T10:17:07","slug":"format","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3753","title":{"rendered":"Format"},"content":{"rendered":"\n<p>The format function can be used to format data. Some common examples include formatting currencies, decimal numbers, or dates.<\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">string format(number|string|datetime $data, string $format, string $culture)<\/code><\/pre>\n\n\n\n<p>This function takes a numerical-, string- or date value as $data, and formats this input based on $format and $culture. Output is a string value.<\/p>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$data:<\/strong> Can be a number, string, or date-time object. <br><strong>$format<\/strong>: A string defining how the $data should be formatted. Should follow <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/standard-numeric-format-strings\">Microsoft standard format specifiers<\/a> (e.g., &#8220;C2&#8221;, &#8220;N1&#8221;).<br><strong>$culture<\/strong>: A string defining the culture the $data formatting should follow. Should follow iana values (e.g. &#8220;en-US&#8221;, &#8220;es-ES&#8221;).<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<p>Below, &#8220;FirstValue&#8221; is formatted in four different ways showcasing various options.<\/p>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"FirstValue\": 1000\n}<\/code><\/pre>\n\n\n\n<p>The names of the values below indicate what the transformation is achieving.<\/p>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    AmericanCurrencyTwoDecimals: format(FirstValue, 'C2', 'en-US'),\n    SpanishCurrencyNoDecimals: format(FirstValue, 'C0', 'es-ES'),\n    AmericanNumberTwoDecimals: format(FirstValue, 'N2', 'en-US'),\n    SpanishNumberTwoDecimals: format(FirstValue, 'N2', 'es-ES')\n}<\/code><\/pre>\n\n\n\n<p>Thus, currencies based on culture, number of decimals, thousands separator, and decimal points are controlled.<\/p>\n\n\n\n<pre title=\"Ouput\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"AmericanCurrencyTwoDecimals\": \"$1,000.00\",\n    \"SpanishCurrencyNoDecimals\": \"1.000 \u20ac\",\n    \"AmericanNumberTwoDecimals\": \"1,000.00\",\n    \"SpanishNumberTwoDecimals\": \"1.000,00\"\n}<\/code><\/pre>\n\n\n\n<p>There are more formatting options available than those showcased here. Please look through the <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/standard-numeric-format-strings\">Microsoft standard format specifiers<\/a> for additional formatting options.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The format function can be used to format data. Some common examples include formatting currencies, decimal numbers, or dates. Syntax This function takes a numerical-, string- or date value as $data, and formats this input based on $format and $culture. Output is a string value. Parameters $data: Can be a number, string, or date-time object. [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":271,"menu_order":50,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3753"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3753"}],"version-history":[{"count":7,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3753\/revisions"}],"predecessor-version":[{"id":3838,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3753\/revisions\/3838"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}