Forum: Ruby for matz to do

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
72eb393f96912d674e0f5c1fb1111ba0?d=identicon&s=25 Dave Rose (bitsmith)
on 2007-07-27 15:08
i'd like to see two new ruby language additions....
1.) in the sprintf formatting command a way to format for business.....
 i.e.... processing payroll chks...with asterik fill AND commas
 and space fill AND commas or anything fill AND commas to do this
  *****$1,312.00
 without having to write a separate def function....

 ...and....
i'm comming from BBX (Business Basic).... a new kind of number... like
Bignum
...but Biznum .... where all intermediate calculations are correctly and
consistently rounded. we have a billing system not written in BBX and
it's always pennies off due to round off error ... there is value in
this...because BBX has it and i've never had to worry about round off
errors
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-07-27 15:18
(Received via mailing list)
On 7/27/07, Dave Rose <bitdoger2@yahoo.com> wrote:
> ...but Biznum .... where all intermediate calculations are correctly and
> consistently rounded. we have a billing system not written in BBX and
> it's always pennies off due to round off error ... there is value in
> this...because BBX has it and i've never had to worry about round off
> errors

Look at BigDecimal
E0ed615bd6632dd23165e045e3c1df09?d=identicon&s=25 Florian Gross (Guest)
on 2007-07-27 15:38
(Received via mailing list)
On Jul 27, 3:08 pm, Dave Rose <bitdog...@yahoo.com> wrote:
> i'm comming from BBX (Business Basic).... a new kind of number... like
> Bignum
> ...but Biznum .... where all intermediate calculations are correctly and
> consistently rounded. we have a billing system not written in BBX and
> it's always pennies off due to round off error ... there is value in
> this...because BBX has it and i've never had to worry about round off
> errors

Try this:

# prelude
require 'rational'
require 'bigdecimal'
require 'bigdecimal/util'

# compute
result = Rational(5) / 23 * 13 / 27

# output
precision = 5
result.to_d(precision).to_s("F") # => "0.10467"

precision = 50
result.to_d(precision).to_s("F") # =>
"0.10466988727858293075684380032206119162640901771337"

What this means is that you are working with maximum precision
whenever one of the numbers involved in an operation is a Rational().

At output time you specify the precision you actually need.

Unfortunately, operations from the Math module will still convert
their arguments to and produce floats.

It would be nice if we'd need to require less files to get that
behaviour. I'd also prefer being able to do result.to_s(precision)
over .to_d().to_s().
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-07-27 15:55
(Received via mailing list)
Florian Gross wrote:

> # output
> precision = 5
> result.to_d(precision).to_s("F") # => "0.10467"

Next, on the "for matz to do" angle, we might need a little lecture here
on
how easily Ruby will let you wrap your methods up in reusable classes,
such
as BizNum. Quite unlike a BASIC...
6d9bf78ca49a017e9e3e6b0357b6c59e?d=identicon&s=25 Peter Hickman (Guest)
on 2007-07-27 16:03
(Received via mailing list)
Dave Rose wrote:
> ...but Biznum .... where all intermediate calculations are correctly and
> consistently rounded. we have a billing system not written in BBX and
> it's always pennies off due to round off error ... there is value in
> this...because BBX has it and i've never had to worry about round off
> errors
>
Being realistic here, in all likely hood you are the expert on this and
not matz or 99.9999% of the Ruby users.

If this is important to you then at least start on the project
(collecting the specifications and the like for Biznum, has this been
implemented in Python or Perl which you might use as a starting point)
and also look around for other Rubyists that are also interested in this
problem who might help you. Set up a Rubyforge project and get things
rolling.

Bear in mind the market for your extensions. The formatting you show
seems to be only valid for UK or US businesses. Will this class be
useful for French, Austrian or Greek business users, other countries
probably have specific rules about how you do accounting (definitely
different formatting rules) - possibly even depending on the business
sector they operate within. This will dictate the pool of talent that
you can draw on. If your solution will only work in the UK then people
with a similar problem in the US are probably not going to be
interested.

Adding extensions to the language just for business users in one or two
countries seems to be asking a lot when you could simply create a new
class to handle it.

Also when trying to drum up support you might consider your writing
style, you come across as a stoner :)
72eb393f96912d674e0f5c1fb1111ba0?d=identicon&s=25 Dave Rose (bitsmith)
on 2007-07-27 18:18

..all good points..to all above ...can one also modify struct class to
do the biznum?
This topic is locked and can not be replied to.