Giter Site home page Giter Site logo

yurymikhailuts / kig-decimal Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 100 KB

Зеркало проекта KigDecimal. Библиотека реализации BigDecimal для kotlin multiplatform (jvm, js)

Home Page: https://gitflic.ru/project/mikhaylutsyury/kig-decimal

License: Other

Kotlin 100.00%
bigdecimal kotlin-multiplatform

kig-decimal's People

Contributors

mrstahlfelge avatar yurymikhailuts avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

mrstahlfelge

kig-decimal's Issues

RoundingMode missing

Hi,

first of all, thanks for going the route by reusing the GWT lib. I always had good experiences with GWT's BigDecimal, while I experience bug after bug with the other Kotlin Multiplatform libs, so I think this is the right way to go.

For me two things are missing so far:

fun String.toBigDecimal() = BigDecimal(this)

(easy to add)

and

fun setScale(newScale: Int, roundingMode: RoundingMode): BigDecimal

I made an attempt to add myself, but I am getting stuck how to add RoundingMode as a type alias. When adding it as an own enum, the whole other type alias is not working any more. Unfortunately, my code depends on the Rounding Mode. My attempt to integrate the lib ended in "Rounding necessary" error (which is a good sign, as it is!)

Also, please translate the license and readme into English.

JS: Int/Long conversion problem, exception catching

Hi again,
during testing, I discovered that it probably is necessary to make some more wrapping around the JS layer. I came across the following problems:

Int/Long conversion problem
BigDecimal.toLongExact() returns an Int (also it should return a Long). This is somehow caused by JS not having a long. However, this means we have a wrong type at runtime and we have exceptions when Int is not sufficient.
To work around this, I converted to String and back to Long in Kotlin code. Maybe there is a better way. This should be handled in the lib's JS layer.

Exceptions are not catched
Exceptions that are thrown in JS code are not catched in Kotlin code. If something in BigDecimal's JS layer throws an error, any error handling in common code is bypassed because catching Throwables does not catch JS errors. We need to use catch (e: dynamic) and rethrow Kotlin exceptions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.