diff options
author | Guillermo Ramos | 2025-02-16 19:09:34 +0100 |
---|---|---|
committer | Guillermo Ramos | 2025-02-16 19:50:26 +0100 |
commit | 91588159234f7fe357a3fd0887367364a71e0df9 (patch) | |
tree | 4763ee048cf9441210a1c19b7a9c78f75844103e | |
parent | e006f43619f8763750baf98f14ffa095f19f2b2b (diff) | |
download | hiccup-91588159234f7fe357a3fd0887367364a71e0df9.tar.gz |
Elm round values
-rw-r--r-- | front/elm.json | 3 | ||||
-rw-r--r-- | front/src/Main.elm | 11 | ||||
-rw-r--r-- | src/bin/cli.rs | 8 |
3 files changed, 12 insertions, 10 deletions
diff --git a/front/elm.json b/front/elm.json index 785c5be..a758c49 100644 --- a/front/elm.json +++ b/front/elm.json @@ -10,7 +10,8 @@ "elm/core": "1.0.5", "elm/html": "1.0.0", "elm/http": "2.0.0", - "elm/json": "1.1.3" + "elm/json": "1.1.3", + "myrho/elm-round": "1.0.5" }, "indirect": { "elm/bytes": "1.0.8", diff --git a/front/src/Main.elm b/front/src/Main.elm index 47edd9d..4d39cb3 100644 --- a/front/src/Main.elm +++ b/front/src/Main.elm @@ -1,5 +1,6 @@ module Main exposing (..) +import Round import Browser import Html exposing (Html, button, div, input, text) import Html.Attributes exposing (max, min, step, type_, value) @@ -36,7 +37,7 @@ capitalDecoder = capitalStr : Capital -> String capitalStr { principal, interest } = - String.concat [ "{principal=", String.fromFloat principal, ", interest=", String.fromFloat interest, "}" ] + String.concat [ "{principal=", Round.round 2 principal, ", interest=", Round.round 2 interest, "}" ] type alias Quota = @@ -121,7 +122,7 @@ init : () -> ( Model, Cmd Msg ) init () = let simSpecs = - { principal = 300000.0, i1 = 2.1, years = 30 } + { principal = 200000.0, i1 = 1.621, years = 30 } req = runSimulation simSpecs @@ -238,14 +239,14 @@ specsView { principal, i1, years } = , onInput (UpdateSimSpecs Principal) ] [] - , text (String.fromFloat principal) + , text (Round.round 2 principal) ] , div [] [ text "Interest rate: " , input [ Html.Attributes.min "0" , Html.Attributes.max "100" - , value (String.fromFloat i1) + , value (Round.round 2 i1) , onInput (UpdateSimSpecs I1) ] [] @@ -269,7 +270,7 @@ specsView { principal, i1, years } = quotaView : Quota -> Html Msg quotaView { period, payed, pending_principal } = - div [] [ text (String.join "\t" [ String.fromInt period, capitalStr payed, String.fromFloat pending_principal ]) ] + div [] [ text (String.join "\t" [ String.fromInt period, capitalStr payed, Round.round 2 pending_principal ]) ] historyView : List Quota -> Html Msg diff --git a/src/bin/cli.rs b/src/bin/cli.rs index 5ca388b..c7672c6 100644 --- a/src/bin/cli.rs +++ b/src/bin/cli.rs @@ -1,11 +1,11 @@ use hiccup::{SimUpdate::*, SimUpdates, Simulation}; fn main() { - let mut sim = Simulation::new(390_000., 0.028, 30); - let updates: SimUpdates = Amortize(12_000.).every(12).and(Amortize(30_000.).at(1)); + // let mut sim = Simulation::new(390_000., 0.028, 30); + // let updates: SimUpdates = Amortize(12_000.).every(12).and(Amortize(30_000.).at(1)); - // let mut sim = Simulation::new(200_000., 0.01621, 30); - // let updates: SimUpdates = SimUpdates::default(); + let mut sim = Simulation::new(200_000., 0.01621, 30); + let updates: SimUpdates = SimUpdates::default(); sim.run(updates); sim.render_table(); |