BigDecimal转为String (2010-11-19 17:23:38)

本文介绍了如何将BigDecimal类型转换为String类型,并通过实例演示了转换过程。同时,文章还强调了BigDecimal中0、0.0与0.00的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BigDecimal转为String

  (2010-11-19 17:23:38)
标签: 

bigdecimal

 

string

 

0.00

 

杂谈

分类: 程序人生

  BigDecimal ble=new BigDecimal("0.00");//若是BigDecimal ble=MathUtils.ZERO; ble为0且什么都不输出

  String bleeeeee=ble.toString();
    if(bleeeeee.equals("0.00")){
   System.out.println("bleeeeee ="+bleeeeee);
  }

 

BigDecimal 类型中0和0.0和0.00是不一样的

 


帮我看一下package com.ever.digitalfactory.ips.base.processmanagement.result; import io.swagger.annotations.ApiModel; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.ever.beeboat.runtime.mvc.param.BaseOutParam; import com.ever.digitalfactory.ips.base.consts.IpsConsts; import lombok.Data; import lombok.EqualsAndHashCode; /** * IPS后台服务-工艺管理-列表查询数据出参基类 * * @author Administrator */ @Data @ExcelIgnoreUnannotated @EqualsAndHashCode(callSuper = true) @ApiModel(IpsConsts.ProcessManagement.TechnologyRegulationProcedureInspection.NAME + IpsConsts.ProcessManagement.TechnologyRegulationProcedureInspection.Methods.LIST + "出参") public class BaseTechnologyRegulationProcedureInspectionListResult extends BaseOutParam { /** * 是否理化 */ @io.swagger.annotations.ApiModelProperty(value = "是否理化", example = "") private Integer isPhysicalChemicalInspection; /** * 检验类型list */ @io.swagger.annotations.ApiModelProperty(value = "检验类型list", example = "") private java.util.List<com.ever.digitalfactory.ips.usage.processmanagement.result.TechnologyRegulationProcedureInspectionInspectTypeListResult> inspectTypeList; /** * 记录方式 */ @io.swagger.annotations.ApiModelProperty(value = "记录方式", example = "") private String recordMethod; /** * 记录要求 */ @io.swagger.annotations.ApiModelProperty(value = "记录要求", example = "") private String recordDemand; /** * 单位名称 */ @io.swagger.annotations.ApiModelProperty(value = "单位名称", example = "") private String unitName; /** * 单位id */ @io.swagger.annotations.ApiModelProperty(value = "单位id", example = "") private String unitId; /** * 下偏差 */ @io.swagger.annotations.ApiModelProperty(value = "下偏差", example = "") private java.math.BigDecimal lowerDeviation; /** * 上偏差 */ @io.swagger.annotations.ApiModelProperty(value = "上偏差", example = "") private java.math.BigDecimal upperDeviation; /** * 检验方法 */ @io.swagger.annotations.ApiModelProperty(value = "检验方法", example = "") private String inspectMethod; /** * 检验项目 */ @io.swagger.annotations.ApiModelProperty(value = "检验项目", example = "") private String inspectName; /** * 工艺规程关联工序ID */ @io.swagger.annotations.ApiModelProperty(value = "工艺规程关联工序ID", example = "") private String technologyRegulationProcedureId; /** * 租户ID */ @io.swagger.annotations.ApiModelProperty(value = "租户ID", example = "") private String companyId; /** * 修改时间 */ @io.swagger.annotations.ApiModelProperty(value = "修改时间", example = "") @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.class) @com.fasterxml.jackson.databind.annotation.JsonSerialize(using = com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer.class) @com.fasterxml.jackson.annotation.JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @com.alibaba.fastjson.annotation.JSONField(format = "yyyy-MM-dd HH:mm:ss") private java.time.LocalDateTime gmtModified; /** * 创建时间 */ @io.swagger.annotations.ApiModelProperty(value = "创建时间", example = "") @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.class) @com.fasterxml.jackson.databind.annotation.JsonSerialize(using = com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer.class) @com.fasterxml.jackson.annotation.JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @com.alibaba.fastjson.annotation.JSONField(format = "yyyy-MM-dd HH:mm:ss") private java.time.LocalDateTime gmtCreate; /** * 主键 */ @io.swagger.annotations.ApiModelProperty(value = "主键", example = "") private String id; /** * 创建人 */ @io.swagger.annotations.ApiModelProperty(value = "创建人", example = "") private String creatorId; /** * 修改人 */ @io.swagger.annotations.ApiModelProperty(value = "修改人", example = "") private String modifiedId; /** * 量具信息 */ @io.swagger.annotations.ApiModelProperty(value = "量具信息", example = "") private java.util.List<com.ever.digitalfactory.ips.usage.processmanagement.result.TechnologyRegulationProcedureInspectionMeasureListResult> measureList; /** * 理化方法List */ @io.swagger.annotations.ApiModelProperty(value = "理化方法List", example = "") private java.util.List<com.ever.digitalfactory.ips.usage.processmanagement.result.TechnologyRegulationProcedureInspectionPhyCheMethodListResult> phyCheMethodList; /** * 理化要求 */ @io.swagger.annotations.ApiModelProperty(value = "理化要求", example = "") private String physicalChemicalStandard; /** * 执行标准 */ @io.swagger.annotations.ApiModelProperty(value = "执行标准", example = "") private String executiveStandard; /** * 标准值 */ @io.swagger.annotations.ApiModelProperty(value = "标准值", example = "") private String standardValue; /** * 样机抽检比例 */ @io.swagger.annotations.ApiModelProperty(value = "样机抽检比例", example = "") private String spotCheckRatio; } 我返回的这个参数是int,为什么查出来的结果变成了string "inspectionList": [ { "companyId": "6ec7b365dd5e4caeab299031c8bd1bfc", "creatorId": "ecf11a2a8d4545c4b256d7178278801c", "executiveStandard": null, "gmtCreate": "2025-06-20 09:44:32", "gmtModified": "2025-06-20 11:08:32", "id": "be867b1abc19d2a9011ed705179738f2", "inspectMethod": "测量", "inspectName": "测试", "inspectTypeList": [ { "companyId": "6ec7b365dd5e4caeab299031c8bd1bfc", "creatorId": "ecf11a2a8d4545c4b256d7178278801c", "gmtCreate": "2025-06-20 09:44:33", "gmtModified": "2025-06-20 11:08:33", "id": "fb87d22120bc7ac5fee7596495b3a61e", "inspectType": "1", "modifiedId": "ecf11a2a8d4545c4b256d7178278801c", "technologyRegulationId": "900b5128a4ab9ed2172392990c5f8082", "technologyRegulationProcedureId": "cabf2545ef10dbf6f8a2b0d2cab3de62", "technologyRegulationProcedureInspectionId": "be867b1abc19d2a9011ed705179738f2" } ], "isFirstArticleInspection": "1", "isFullInspection": "1", "isPhysicalChemicalInspection": "0", "isQualityGate": "1", "isRandomInspections": "1", "isSelfChecking": "1", "isSpecializedInspection": "1", "lowerDeviation": 2, "measureList": [], "modifiedId": "ecf11a2a8d4545c4b256d7178278801c", "phyCheMethodList": [], "physicalChemicalStandard": null, "recordDemand": "0", "recordMethod": null, "spotCheckRatio": null, "standardValue": "22", "technologyRegulationProcedureId": "cabf2545ef10dbf6f8a2b0d2cab3de62", "unitId": "9f8b6e1967e9d9e603634fefe0704a3d", "unitName": "M", "upperDeviation": 22 } ],
06-21
25/07/10 02:34:54 INFO mapreduce.Job: Task Id : attempt_1752127434545_0022_m_000000_0, Status : FAILED Error: java.io.IOException: Can't export data, please check task tracker logs at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:112) at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:39) at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146) at org.apache.sqoop.mapreduce.AutoProgressMapper.run(AutoProgressMapper.java:64) at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341) at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:422) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1758) at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158) Caused by: java.lang.NumberFormatException: For input string: "2025-07-10 00:00:00" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Long.parseLong(Long.java:589) at java.lang.Long.valueOf(Long.java:803) at D_H_HTTP_APPTYPE.__loadFromFields(D_H_HTTP_APPTYPE.java:521) at D_H_HTTP_APPTYPE.parse(D_H_HTTP_APPTYPE.java:473) at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:83) ... 10 more Container killed by the ApplicationMaster. Container killed on request. Exit code is 143 Container exited with a non-zero exit code 143
07-11
2025-03-09T19:46:32.300+08:00 ERROR 4464 — [ CrawlerTask-1] c.x.backend.service.PriceCrawlerService : [source1] 网络请求异常: HTTP error fetching URL. Status=404, URL=[https://example.com/price?id=P123]package com.xymzsfxy.backend.service; import com.xymzsfxy.backend.entity.PriceHistory; import com.xymzsfxy.backend.entity.Product; import com.xymzsfxy.backend.repository.PriceHistoryRepository; import com.xymzsfxy.backend.repository.ProductRepository; import org.jsoup.Jsoup; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.context.annotation.Bean; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.test.context.TestPropertySource; import java.math.BigDecimal; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.io.IOException; import org.jsoup.nodes.Document; import static org.awaitility.Awaitility.await; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; // 测试类注解 @SpringBootTest @EnableAsync @TestPropertySource(properties = { “crawler.sources.source1=https://example.com/price?id=%s”, “crawler.selectors.source1=div.price” }) class PriceCrawlerServiceTest { @Autowired private PriceCrawlerService priceCrawlerService; @MockBean private ProductRepository productRepository; @MockBean private PriceHistoryRepository priceHistoryRepository; @SpyBean private PriceCrawlerService spyPriceCrawlerService; @TestConfiguration static class TestConfig { @Bean public JsoupWrapper jsoupWrapper() { return new JsoupWrapper(); } } @Test void shouldSavePriceWhenCrawlSuccess() throws Exception { // 模拟测试数据 Product mockProduct = new Product(); mockProduct.setId(1L); mockProduct.setExternalId("P123"); // 配置Mock行为 when(productRepository.findById(1L)).thenReturn(Optional.of(mockProduct)); doReturn(new BigDecimal("299.00")).when(spyPriceCrawlerService).extractPrice(any(), anyString()); // 执行测试方法 priceCrawlerService.crawlPrices(1L); // 验证异步执行结果 await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { verify(priceHistoryRepository, times(1)).save(any(PriceHistory.class)); verify(productRepository, times(1)).save(argThat(p -> p.getLatestPrice().equals(new BigDecimal("299.00")) )); }); } @Test void shouldHandleMissingProduct() { when(productRepository.findById(999L)).thenReturn(Optional.empty()); // 直接调用方法,若抛出异常测试会自动失败 priceCrawlerService.crawlPrices(999L); verify(priceHistoryRepository, never()).save(any()); } } // 辅助类用于模拟网页请求 class JsoupWrapper { Document fetchDocument(String url) throws IOException { // 模拟返回包含价格的HTML文档 String html = “<html><div class=‘price’>¥299.00</div></html>”; return Jsoup.parse(html); } }如何用正确的网址验证
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值