maintenance: title: Formats numbers into strings with commas;; mlmname: SYS_FORMAT_NUMBER;; arden: version 2.5;; version: 18.4;; institution: Allscripts,System MLM ;; author: Allscripts Healthcare Solutions, Inc.;; specialist: ;; date: 2018-10-26;; validation: testing;; /* P r o p r i e t a r y N o t i c e */ /* Unpublished (c) 2013 - 2018 Allscripts Healthcare, LLC. and/or its affiliates. All Rights Reserved. P r o p r i e t a r y N o t i c e: This software has been provided pursuant to a License Agreement, with Allscripts Healthcare, LLC. and/or its affiliates, containing restrictions on its use. This software contains valuable trade secrets and proprietary information of Allscripts Healthcare, LLC. and/or its affiliates and is protected by trade secret and copyright law. This software may not be copied or distributed in any form or medium, disclosed to any third parties, or used in any manner not provided for in said License Agreement except with prior written authorization from Allscripts Healthcare, LLC. and/or its affiliates. Notice to U.S. Government Users: This software is {{{SINGLE-QUOTE}}}Commercial Computer Software{{{SINGLE-QUOTE}}}. All product names are the trademarks or registered trademarks of Allscripts Healthcare, LLC. and/or its affiliates. */ /* P r o p r i e t a r y N o t i c e */ library: purpose: Format a number as a string, using conversion rules: Commas are used to delimit thousands Exponent notation is never used Trailing zeros which occur following the decimal point and at the end of the string are trimmed off. ;; explanation: ;; keywords: ;; knowledge: type: data-driven;; data: ( num ) := argument; ;; evoke: // called from another MLM ;; logic: if num is not number then result := num; conclude true; endif; result := num formatted with "%,f"; chars := extract characters result; // loop through chars, and determine if there are trailing zeros trailing_pos := 0; found_trailing := false; found_decimal := false; pos := 0; for ch in chars do if (ch = ".") then found_decimal := true; found_trailing := true; trailing_pos := pos; elseif (ch = "0") and (found_decimal = true) and (found_trailing = false) then found_trailing := true; trailing_pos := pos; elseif (ch <> "0") and (found_trailing = true) then found_trailing := false; endif; pos := pos + 1; enddo; if found_trailing then result := string (first trailing_pos from chars); endif; conclude true; ;; action: return result; ;; end: