For matz to do


#1

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


#2

On 7/27/07, Dave R. removed_email_address@domain.invalid 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


#3

On Jul 27, 3:08 pm, Dave R. removed_email_address@domain.invalid 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().


#4

Florian G. 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…


#5

…all good points…to all above …can one also modify struct class to
do the biznum?


#6

Dave R. 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 :slight_smile: