Round stock change percent value

This commit is contained in:
Erik C. Thauvin 2025-05-10 05:16:44 -07:00
parent 5c3eaf232d
commit 066e3f81e9
Signed by: erik
GPG key ID: 776702A6A2DA330E
2 changed files with 5 additions and 3 deletions

View file

@ -46,6 +46,7 @@ import org.pircbotx.hooks.types.GenericMessageEvent
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.io.IOException import java.io.IOException
import java.math.RoundingMode
import java.net.URL import java.net.URL
import java.time.Instant import java.time.Instant
import java.time.ZoneId import java.time.ZoneId
@ -180,7 +181,8 @@ class StockQuote2 : AbstractModule() {
) )
add( add(
NoticeMessage( NoticeMessage(
"Change: ".padEnd(pad).prependIndent() + change + " [$changePercent%]" "Change: ".padEnd(pad).prependIndent() + change
+ " [${changePercent.setScale(2, RoundingMode.DOWN)}%]"
) )
) )
add( add(
@ -264,7 +266,7 @@ class StockQuote2 : AbstractModule() {
val name = result.getString("description") val name = result.getString("description")
add( add(
NoticeMessage("${symbol.bold()}: $name".prependIndent()) NoticeMessage("${symbol.bold().padEnd(10)} $name".prependIndent())
) )
if (i >= 4) { if (i >= 4) {

View file

@ -161,7 +161,7 @@ class StockQuote2Test : LocalProperties() {
var hasGoog = false var hasGoog = false
for (msg in messages) { for (msg in messages) {
if (msg.msg.matches("\\s+\u0002GOOG\u0002: .*".toRegex())) { if (msg.msg.matches("\\s+\u0002GOOG\u0002\\s+.*".toRegex())) {
hasGoog = true hasGoog = true
break break
} }