This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

.000000 overload!

Old posts that have not been replied to for several years.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

.000000 overload!

Post by NewzUK »

Hi,

I use a stock quote script in my channels, but users complain about the anount of numbers displayed after the decimal point, like this:

<News24> » CAC: 2824.39 +52.1300011 (+1.88%)

so I'm wondering if it's possible to limit the number so it cuts it down to just 2 numbers after the . so it's more like:

<News24> » CAC: 2824.39 +52.13 (+1.88%)

Here is the portion of the script for the quotes:

proc pub:quote { nick uhost handle channel arg } {
set [lindex [info args pub:quote] 4] [string trimleft [subst $[lindex [info args pub:quote] 4]] !]
foreach _IG [uplevel #0 {set IGwords}] { if {[string equal -nocase $_IG [lindex [split $arg] 0]]} { return } }
if {[llength $arg]==0} {
putserv "NOTICE $nick :0,2 please type \002!news\002 for options "
} else {
set stock [string toupper [lindex $arg 0]]
set query "http://finance.yahoo.com/d/quotes.csv?s ... 4mv&e=.csv"
set token [http::geturl $query]
set all [http::data $token]
regsub -all \" $all "" all
set all [split $all ","]
if {[lindex $all 2]!="0.00"} {
putserv "PRIVMSG $channel :\0037» [lindex $all 0]:\003 [lindex $all 2] \002[lindex $all 3]\002 ([lindex $all 4]) \0037 Time:\003 [lindex $all 1] USET \0037 Low-High:\003 [lindex $all 5] \0037 Volume:\003 [lindex $all 6]"
} else {
putserv "PRIVMSG $channel :\002 [lindex $all 0]\002 symbol not found"
}
}
}


The part of the quote to be shortened is: [lindex $all 3]

thanks!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I am glad you told us the part of the code to be shortened, as the code you pasted doesn't produce the example you pasted. It generates a lot more detail, thus throwing a whole lot of "Am I sure this is the one to modify" into it all.

However, using the part you claim needs modifying, use.

Code: Select all

set round [join [lindex [split [lindex $all 3] .] 0] [string range [lindex [split [lindex $all 3] .] 1] 0 1] .]
You should now use the variable $round in place of the "[lindex $all 3]"
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

thanks - as I read your reply, I realised that I've already varied the index3 part on another piece of script that I added to change the + & - colours to red & green...here is the *actual* script this time, where index 3 became $test


proc pub:quote { nick uhost handle channel arg } {
set [lindex [info args pub:quote] 4] [string trimleft [subst $[lindex [info args pub:quote] 4]] !]
foreach _IG [uplevel #0 {set IGwords}] { if {[string equal -nocase $_IG [lindex [split $arg] 0]]} { return } }
if {[llength $arg]==0} {
putserv "NOTICE $nick : 0,2 please type \002!news\002 for options "
} else {
set stock [string toupper [lindex $arg 0]]
set query "http://finance.yahoo.com/d/quotes.csv?s ... 4mv&e=.csv"
set token [http::geturl $query]
set all [http::data $token]
regsub -all \" $all "" all
set all [split $all ","]
set test [string map [list + \00309+ - \00304-] [lindex $all 3]]
set test2 [string map [list + \00309+ - \00304-] [lindex $all 4]]
if {[lindex $all 2]!="0.00"} {
putserv "PRIVMSG $channel :\0037» [lindex $all 0]:\003 [lindex $all 2] $test ($test2)\003 [lindex $all 1] USET \0037 Low-High:\003 [lindex $all 5] \0037 Volume:\003 [lindex $all 6]"
} else {
putserv "PRIVMSG $channel :\002 [lindex $all 0]\002 symbol not found"
}
}
}
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

just a little note..
this will make 52.1399999 show as 52.13 and not 52.14 as would perhapse be the right output...
you have to add a check to see if the 3rd char after the . is larger or equal to 5 and then increase the 2nd char by one if you want it to be really accurate
Elen sila lúmenn' omentielvo
t
tk421

Post by tk421 »

i don't quite follow all your script, but surely you can modify your code with the format command:

set $number 52.13000011

set number [format %.2f $number]

would make $number look like 52.13 (rounded properly to 2 dec places)

to add this in your code you could do somthing like:

set all [lreplace $all 3 3 "[format %.2f [lindex $all 3]]"]
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

thanks - that number I quoted was an example only and the script needs to cut down any number to just 2 places after the decimal point...

the problem is that [lindex $all 3] has already been changed to $test by another piece of script in the proc that changes the colours if the values are + or -, so I'm just not sure how to proceed...

thanks.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

set round [join [lindex [split $test .] 0] [string range [lindex [split $test .] 1] 0 1] .]
Elen sila lúmenn' omentielvo
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

that makes the bot post nothing to the chan - I inserted that line under the 'set test' one...

:-?
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

am getting the error:

Tcl error [pub:quote]: wrong # args: should be "join list ?joinString?"
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Make sure that is one line.
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

yep I put it in one line in this part of the script:

set test [string map [list + \00309+ - \00304-] [lindex $all 3]]
set round [join [lindex [split $test .] 0] [string range [lindex [split $test .] 1] 0 1] .]


still same error
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

set round [join [list [lindex [split $test .] 0] [string range [lindex [split $test .] 1] 0 1]] .]
just a little list command missing
or you can do:

Code: Select all

set round [join "[lindex [split $test .] 0] [string range [lindex [split $test .] 1] 0 1]" .]
both will work
Elen sila lúmenn' omentielvo
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

hi - sorry but neither of those are working - is still displaying same as before...
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

hmm are you sure you rehashed after updating the script?... cause I just tested it on one of my eggdrops and it worked like a dream..
Elen sila lúmenn' omentielvo
N
NewzUK
Master
Posts: 200
Joined: Mon Nov 18, 2002 3:10 am
Location: Auckland, New Zealand
Contact:

Post by NewzUK »

yes I've rehashed and this is still the result:

[09:07:57] <NewzBoy> !q AOL
[09:08:00] <News24> » AOL: 10.139 -0.131000519 (-1.28%) 3:07pm USET Low-High: 9.90 - 10.38 Volume: 13903500

I placed one of those lines of script you gave me just after the 'set test' lines - is that ok?

thanks.
Locked