ID:926187
 
(See the best response by Zaoshi.)
I'm wondering if it's possible to use one numerical value to set the value of four other variables.

The four variables are copper for the 1s place, silver for the 10s place, gold for the 100s place and platinum for the 1000s place. They are the players currency. The item value would be translated into those four currencies, which would then be displayed individually.

Like so...

item_value=37

37 = 37 copper
or
3 silver 7 copper

item_value=1424

1424 = 1424 copper
or
14 gold 2 silver 4 copper
or
1 platinum 4 gold 24 copper
or
1 platinum 4 gold 2 silver 4 copper

item_value=27893

27893 = 27893 copper
or
278 gold 9 silver 3 copper
or
27 platinum 8 gold 93 copper
or
27 platinum 8 gold 9 silver 3 copper
round() always returns the floor of the sent value. Round off for the places and divide by the value.

item_value = 27001
var/i = item_value

if(i >= 1000)
platinum = round(i, 1000)/1000 // returns 27
i = i - round(i, 1000) // This takes away the thousands place, in this case leaving you with 1
if(i >= 100)
gold = round(i, 100)/100
i = i - round(i, 100)
if(i >= 10)
silver = round(i, 10)/10
i = i - round(i, 10)
if(i >= 1)
copper = round(i)
ah thanks!
In response to Albro1
Best response
Albro1 wrote:
round() always returns the floor of the sent value. Round off for the places and divide by the value.
According to reference that is not true. Since you specify to round to 1000 it'll round to nearest, not floor

My approach would be
item_value = 1234

platinum = round(item_value / 1000)
gold = round(item_value % 1000 / 100)
silver = round(item_value % 100 / 10)
copper = item_value % 10
Nothing in the reference suggests otherwise. round() always floors. In fact, the reference proves my point. In their example, they did round(-1.45), which results in -2. Therefore - floor'd.
Format:
round(A)
round(A,B)

The first format returns the floor of A (the largest integer less than or equal to A).
The second format rounds A to the nearest multiple of B.

Did you even bother to read reference?

round(-1.45) will floor, round(1.45,1.5) rounds.
It is only if you specify the second argument (B) that it will round to THAT value's nearest multiple. Other than that, it will always floor.

It's also why we have this ceil (rounding up, instead of down) shortcut, using the usage of negatives with flooring.

#define ceil(x) (-round(-(x)))


normally, round(-1.45) will become -2, and round(1.45) will become 1. to ceil a positive, you just negate it, and then negate the rounded value, thus the ceil shortcut.
It still floors. I guess you could deceive it into appearing to not floor by providing an exact amount for the second argument. Like SSX said though, it rounds to the nearest multiple. 1.45 is closer to 1.5 than it is to it's next multiple, 3.
In response to Super Saiyan X
IMO round() just needs to be turned into floor() and that ceil() shortcut needs to be put into BYOND. It's a very simple thing that's been put off for far too long.
Problem is, your answer to OP's question is wrong.
item_value = 27001
platinum = round(i, 1000)/1000 // returns 27

item_value = 27501
platinum = round(i, 1000)/1000 // returns 28, expected 27
In response to Zaoshi
Thanks for pointing that out, that is a legitimate problem. I think you should thank us for pointing out your mistake before pointing out ours, though.
I can't see where I made mistake.
In my very first post I told round(a) floors and round(a, b) rounds by linking reference.
In response to Zaoshi
Zaoshi wrote:
I told round(a) floors
No, you didn't.

Anyways, another solution would be to convert it to a text string and parse it.
Since you specify to round to 1000 it'll round to nearest, not floor

I can't tell whether you're trolling or not.