Giter VIP home page Giter VIP logo

d-money's Introduction

d-money's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

d-money's Issues

bug! EUR("1.23456") ==> ctor ==> 3.3456EUR !

$ cat m.d
/+dub.sdl:
dependency "money" version="~>2.3.1"
+/

import std.stdio;
import money;

alias EUR = currency!("EUR");

void main() {
  EUR x = EUR( 1.23456 );
  EUR y = EUR("1.23456");
  writeln(x);
  writeln(y);
  assert(x == y);
}

$ dub m.d
1.2346EUR
3.3456EUR
[email protected](15): Assertion failure
----------------
??:? _d_assertp [0x52b005]
m.d:15 _Dmain [0x4dec36]
Program exited with code 1

The reason is pow10(x) doesn't handle negative x at all.

https://github.com/qznc/d-money/blob/master/source/money.d#L64

when called from

https://github.com/qznc/d-money/blob/master/source/money.d#L107

with x = -1

BTW, why use a recursive function instead of a simple loop to calc pow10?

import and template

I get this:

Joels-MacBook-Pro:Money joelcnz$ dub
Performing "debug" build using dmd for x86_64.
money 1.0.0: target for configuration "library" is up to date.
jmoney ~master: building configuration "application"...
source/app.d(6,14): Error: template instance money!"EUR" money is not a template declaration, it is a import
dmd failed with exit code 1.
Joels-MacBook-Pro:Money joelcnz$

I think the module needs a new name.

'currency' is not defined

I not sure I understand dub.

I get this with the code below:

Joels-MacBook-Pro:Money joelcnz$ dub
Performing "debug" build using dmd for x86_64.
money 1.0.0: target for configuration "library" is up to date.
jmoney ~master: building configuration "application"...
source/app.d(6,14): Error: template instance currency!"EUR" template 'currency' is not defined
dmd failed with exit code 1.
Joels-MacBook-Pro:Money joelcnz$

{
"name": "jmoney",
"description": "A minimal D application.",
"dependencies":
{
"money": "~>1.0.0"
}
}

[code]
import std.stdio;

import money;

void main() {
alias EUR = currency!("EUR");

assert(EUR(100.0001) == EUR(100.00009));
assert(EUR(3.10) + EUR(1.40) == EUR(4.50));
assert(EUR(3.10) - EUR(1.40) == EUR(1.70));
assert(EUR(10.01) * 1.1 == EUR(11.011));

writefln("%d", EUR(3.6)); // "4EUR"
writefln("%f", EUR(3.141592)); // "3.1416EUR"
writefln("%.2f", EUR(3.145)); // "3.15EUR"

}
[/code]

string to d-money

How do I take a string and convert it into the money number?

Example:

alias EUR = currency!("EUR");

EUR cost;
cost = EUR("1.23");

EUR(0.001234) becomes EUR(0.1234)???

Hi, I've the following small test example:

void main()
{
    alias EUR = currency!("EUR", 6);
    
    import std.stdio;
    writeln(EUR(0.001234));
}

But writeln() prints "0.1234EUR" instead of "0.001234EUR". I also tried writefln() but the result as the same. Am I doing something wrong?

assert(EUR(100.0001) == EUR(100.00009)); // wtf?!

Hi!

Sorry for my stupid question, but I can't understand what means:

assert(EUR(100.0001) == EUR(100.00009));

As I understand, IRL 100.0001 Euros isn't equal 100.00009 Euros - this is different amounts. And, for example, if I will use this lib for counting of total after some bank/stock exchange transaction this behaviour can't help me to find calculation errors.

currency.this(string) isn't constructs negative values

/+ dub.sdl:
name "hello_world"
dependency "money" version="*"
+/

import std.stdio;
import money;

alias T1 = currency!("T1", 2);
alias T2 = currency!("T2", 2, roundingMode.UNNECESSARY);

void main() {
    auto t1 = T1(-123.45);
    auto t2 = T1("-123.45");

    t1.writeln; // -123.-45T1 (extra minus in toString?)
    t2.writeln; // positive value, but should be negative

    assert(t1 == t2); // failure
}
$ dub run union_bug.d  --single
Performing "debug" build using /usr/bin/dmd for x86_64.
money 2.3.0: target for configuration "library" is up to date.
hello_world ~master: building configuration "application"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running ./hello_world 
-123.-45T1
123.45T1
core.exception.AssertError@union_bug.d(19): Assertion failure
----------------
??:? _d_assertp [0x77087198]
union_bug.d:19 _Dmain [0x7703cfaf]
Program exited with code 1

we need add opCast, e.g. back to double

e.g. after calculating the money value using this library, the value needs to feed into another library for some math operation (or for drawing a chart, i.e money => pixel height), which takes D native type double.

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.