From: Jano Svitok Date: 2008-04-23T22:35:09+09:00 Subject: Re: Negative nums On Tue, Apr 22, 2008 at 4:17 PM, Tim Wolak wrote: > Morning all, > > I sent an email on this yesterday and needed to give you guys some example > code. Below is some code I have for grabbing the numbers I need from lines > in a text file that we receive via FTP. My big concern is the negative > numbers for accounts which are indicated by a position in the file where 0 > is a postive number and ­ is a negative number. What is the best way to get > my account balance and make it a negative number? Iım not sure Iım doing it > the correct way in this script. what about: > class Info > attr_reader :acct, :money > > def initialize(filename) > @acct = File.new(filename, "r") > end > f = Info.new("Balances20080415.txt") > act = f.acct > act.each do |list| > #covert me to a string > futbal = list.to_s > #Pull accounts > office = futbal[22..24] > if office == "RPT" > next > else > acctnum = futbal[24..28] > end > #Pull Liquidating values > lv = futbal[217..231] > #Pull LV Indicator is_negative = futbal[215..215] == '-' value = lv.to_f/1000 value = -value if is_negative puts acctnum," ",value > end or (though not very readable) value = futbal[217..231].to_f / ((futbal[215..215] == '-') ? -1000 : 1000) or a bit better: value = futbal[217..231].to_f / 1000 * ((futbal[215..215] == '-') ? -1 : 1)