for $value in $xmlReport/csv/record/Payment_Amount where $value castable as xs:double return xs:double($value)
That errors out! [XPTY0004] Cannot convert element()* to xs:double+: $xmlReport_1/element(csv)/element(record)/element(Payment_Amount)[. castable as xs:double].
Did you get this error message for the suggested "for" clause, or a let clause?
I conclude from this that NaN is castable as xs:double which surprised me when I first tried something like this, but which does make sense in as much as NaN has to be pseudo-numeric.
Exactly: NaN is a valid double value (as is INF and -INF).
let $made as xs:double+ := for $value in $xmlReport/csv/record/Payment_Amount where $value castable as xs:double return $value
doesn't strike me as obviously wrongly typed on $made. I'd expect that to fail without the where clause but to be OK with it.
The XQuery pandora box provides a lot of type conversions that are all working slightly different: If you specify a type after the let clause, it is (close to) identical to the "treat as" expression. Treating values as another values won’t trigger explicit casts; this is your element nodes won’t be converted to doubles.
However, if you specify types in functions, …
declare function local:bla($made as xs:double+) { ... }
…the values will be "promoted" to the specific type (and this is similar to casts).