How to multiple two values of type driver.Value

44 Views Asked by At

I have two variables, both are of type driver.Value, is there a way to multiply them?

This is a very primitive example:

var a driver.Value
var b driver.value
result := a*b

but getting an error like invalid operation: operator * not defined on a (variable of type driver.Value)

Do I need to convert it to a float or a different type in order to do this?

1

There are 1 best solutions below

0
Eli Davis On

According to the docs, driver.Value can be one of many types.

So first you need to assert the type you're expecting, then do your multiplication.

var a driver.Value
var b driver.value

aF := a.(float64)
bF := b.(float64)

result := aF*bF