Willkommen, Gast Benutzername: Passwort: Angemeldet bleiben:

## Utilizing EM to display grouped thousands with trailing zeros (e.g., 2,435.60) 1 Jahr 4 Monate her #102966

 duvemyster OFFLINE Fresh Lemon Beiträge: 17 Dank erhalten: 4 Karma: 1 What's an easier way than the following to display grouped thousands with trailing zeros utilizing the Expression Manager (EM)? In the following pieces leading up to the example, NUMBER_CALCULATION = 2435.604321 Utilizing number_format leads to an integer with grouped thousands: number_format(NUMBER_CALCULATION) = 2,436. (Specifying number_format(NUMBER_CALCULATION,2) with precision would be nice, but that syntax isn't expected to work as it isn't specified in implemented functions.) Adding a "floor" inside "number_format" ensures that it always rounds down: number_format(floor(NUMBER_CALCULATION)) = 2,435. Utilizing sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION)) gives us the decimals including trailing zeros, though it also has a beginning zero = 0.60. Incorporating "substr" can remove the beginning zero: substr(sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION)),1,3) = .60. Then "join" can be employed to string #3 and #5 from above together: join(number_format(floor(NUMBER_CALCULATION)),substr(sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION)),1,3)) = 2,435.60 What's a shorter way to accomplish this with existing EM implemented functions? Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Utilizing EM to display grouped thousands with trailing zeros (e.g., 2,435.60) 1 Jahr 4 Monate her #103002

 DenisChenu ONLINE Moderator Lime Beiträge: 7151 Dank erhalten: 979 Karma: 286 Hi, Not sure the better way, but : EM number_format MUST be upgraded to accept \$decimals . Please : put a feature request. Denis Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?). A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous Official LimeSurvey Partner | Web development | SkeletonQuest, RWD for LimeSurvey Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Utilizing EM to display grouped thousands with trailing zeros (e.g., 2,435.60) 1 Jahr 4 Monate her #103258

 duvemyster OFFLINE Fresh Lemon Beiträge: 17 Dank erhalten: 4 Karma: 1 feature request submitted as "Upgrade EM number_format to accept \$decimal". Der Administrator hat öffentliche Schreibrechte deaktiviert. Folgende Benutzer bedankten sich: DenisChenu

## Utilizing EM to display grouped thousands with trailing zeros (e.g., 2,435.60) 1 Jahr 4 Monate her #103522

 duvemyster OFFLINE Fresh Lemon Beiträge: 17 Dank erhalten: 4 Karma: 1 Note: There is a flaw in the logic at the top of this post. A trailing .9999 would be added in as .00 without increasing the one's place. The following corrects this: Where NUMBER_CALCULATION = 2435.995 Utilizing number_format leads to an integer with grouped thousands: number_format(NUMBER_CALCULATION) = 2,436. Adding a "floor" inside "number_format" ensures that it always rounds down: number_format(floor(NUMBER_CALCULATION)) = 2,435. (However, we want this rounded up when decimals are .995 - .999 which round up to 1.00.) Utilizing sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION)) gives us the decimals including trailing zeros, though this particular example = 1.00. The one's place would need to be raised in this example but not in instances of 0.00-0.99, so: number_format(floor(NUMBER_CALCULATION + sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION))) = 2,436. Incorporating "substr" removes the beginning zero or one: substr(sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION)),1,3) = .00. Then "join" can be employed to string #4 and #5 from above together: join(number_format(floor(NUMBER_CALCULATION + sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION)))),substr(sprintf("%.2f", round(NUMBER_CALCULATION,2) - floor(NUMBER_CALCULATION)),1,3)) = 2,436.00 Letzte Änderung: 1 Jahr 4 Monate her von duvemyster. Begründung: typos Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd