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
On 7/27/07, Dave R. [email protected] 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
On Jul 27, 3:08 pm, Dave R. [email protected] 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().
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…
…all good points…to all above …can one also modify struct class to
do the biznum?
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