Skip to content

Commit

Permalink
Warning related to use of decimal in datamodels
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar committed Jun 11, 2024
1 parent c13f60e commit 96e1e27
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions content/app/development/data/data-modeling/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ The data model defines the data that can be submitted through an app and the all
Currently, we only support uploading XSD data models.
When uploading an XSD model `<model>.xsd`, the tool will generate the following files: `<model>.cs`, `<model>.schema.json`, and `<model>.metadata.json` (see [Data Model Files](#data-model-files-for-applications)).

{{% notice warning %}}
Depending on the XSD schema, the Studio generator will output `decimal` properties for the C# classes.
_decimal_ is a 128bit floating point number that is not fully representable in the JavaScript (JS) frontend of an Altinn app.
If you use calculations to fill _decimal_ property values you may end up using enough precision that some decimal digits
are lost when deserialized in JS. In this case you will not be able to update the property from the frontend.
If you calculate values with _decimal_ precision, you should make sure the end result fits into `double`/64bit precision. Example:
```csharp
dataModel.Result = (decimal)(double)(3.33m / 3.333m)
```
In the future we will improve data model generation to mitigate this.
{{% /notice %}}

1. Click _Last opp datamodell_ (_Upload Data Model_) from the homepage if there are no existing data models or _Last opp_ (_Upload_) from the
toolbar at the top of the tool.
2. Select an XSD data model file in the file picker and click _Last opp_.
Expand Down
12 changes: 12 additions & 0 deletions content/app/development/data/data-modeling/_index.nb.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ Datamodellen definerer hvilke data som kan sendes inn via en app, og hvilket for
Vi støtter pr. nå kun opplasting av XSD datamodell.
Ved opplasting av XSD-modell `<model>.xsd` vil verktøyet generere følgende filer: `<model>.cs`, `<model>.schema.json` og `<model>.metadata.json` (se [datamodell-filer](#datamodeller-for-applikasjoner)).

{{% notice warning %}}
For noen XSD skjema vil generatoren i Studio opprette properties av type `decimal` i C# klassene.
_decimal_ representerer et 128bit desimaltall som ikke er representerbart/kompatibelt med tall-typen i JavaScript (JS) frontend for Altinn apper.
Hvis du bruker _decimal_ for å kalkulere verdien til en _decimal_ property så kan du ende opp med å bruke nok presisjon til at noen
desimaler forsvinner innen tallet er deserialisert i JS. Isåfall vil ikke verdien kunne oppdateres fra frontenden.
Hvis du kalkulerer verdier med _decimal_ presisjon bør du sørge for at sluttresultatet passer inn i `double`/64bit presisjon. Eksempel:
```csharp
dataModel.Result = (decimal)(double)(3.33m / 3.333m)
```
I fremtiden vil vi forbedre datamodell-generatoren for å unngå dette.
{{% /notice %}}

1. Klikk på _Last opp datamodell_ fra startsiden om det ikke er noen eksisterende datamodeller eller _Last opp_ fra
verktøylinjen øverst i verktøyet.
2. Velg en XSD datamodell-fil i filvelgeren og klikk _Last opp_.
Expand Down

0 comments on commit 96e1e27

Please sign in to comment.